请问在php中怎么实现读一条记录就把指针移到下一条的效果?类似asp的rs.movenext
代码如下:
<?php
$bigSql = "select * from product_big_class";
mysql_query("set names 'gb2312'");
$result = mysql_query($bigSql);
$bigSqlNum = mysql_num_rows($result);
$halfBigNum = ceil($bigSqlNum/2);
?><div style="float:left;width:250px;padding-left:10px;">
<?php
$rs = mysql_fetch_object($result);
for($i=1;$i<=$halfBigNum;$i++){
?>
<div style="height:25px;"><a href="<?=$rs->big_class_id?>" class="show"><?=$rs->big_class_name?></a></div>
<?php
mysql_data_seek($result,$i);
}
?>
好像不对,现在的结果是读同一条记录$halfBigNum次,请高手指教。
代码如下:
<?php
$bigSql = "select * from product_big_class";
mysql_query("set names 'gb2312'");
$result = mysql_query($bigSql);
$bigSqlNum = mysql_num_rows($result);
$halfBigNum = ceil($bigSqlNum/2);
?><div style="float:left;width:250px;padding-left:10px;">
<?php
$rs = mysql_fetch_object($result);
for($i=1;$i<=$halfBigNum;$i++){
?>
<div style="height:25px;"><a href="<?=$rs->big_class_id?>" class="show"><?=$rs->big_class_name?></a></div>
<?php
mysql_data_seek($result,$i);
}
?>
好像不对,现在的结果是读同一条记录$halfBigNum次,请高手指教。
// 连接,选择数据库
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');// 执行 SQL 查询
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());// 用 HTML 显示结果
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";// 释放结果集
mysql_free_result($result);// 关闭连接
mysql_close($link);
?>
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb"); $result = mysql_query("SELECT id, name FROM mytable"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
} mysql_free_result($result);
?>
你复制的是php手册上的吧,我刚刚正在看呢,不过还是不符合需求。
echo "<table><tr>";
while($row = mysql_fetch_array($query))
{
echo "<td>".$row['field']."</td>";
echo $i%2==0?"":"</tr><tr>";
}
echo "<table>";
然后用循环。