假设我有一个查询"select username from users“。我希望将此查询输出到PHP页面,但在每隔10行之后,我希望显示我自己的自定义文本。有什么想法吗?它将继续从第11个记录开始。
发布于 2010-07-16 01:53:37
$count = 0;
while (false !== ($row = mysql_fetch_array($result))) {
//output your row
++$count;
if (($count % 10) == 0) {
//output your special row
}
}发布于 2010-07-16 01:07:23
最简单的方法是拉回数据表,循环通过行,写出每一行,同时跟踪您所在的行。然后,每十次迭代,写出你的自定义消息。
发布于 2010-07-16 01:11:13
如果您使用PDO运行mysql查询,则可以在PHP中创建一个变量,然后通过该变量限制查询。
这是一个不完整的示例,但您可能会明白其中的含义。
<?php
$first = 0;
$second = 9;
$stmt = $db->prepare('select username from users limit :first, :second');
$stmt->bindParam(':first', $first);
$stmt->bindParam(':second', $second);
$stmt->execute();
#loop through your results here and then have a custom message,
#then change your variable values and execute the statement again.
#Repeat this until there are no more rows.
?>https://stackoverflow.com/questions/3257995
复制相似问题