【发布时间】:2011-07-27 01:21:12
【问题描述】:
目前我正在使用 WHERE 循环在我的数据库中显示 2 列信息。代码如下:
$sql2 = sprintf($rawsql2, mysql_real_escape_string($id));
$result2 = mysql_query($sql2);
/*These if & while statements decide whether or not the information should be displayed. If no results are returned from the query above then an alternative message is shown.*/
if (mysql_num_rows($result2) > 0) {
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
echo $row["open"] . "-" . $row["close"] . "<br/><br/>";
}
}
else {
echo "Error";
}
这会输出以下内容:
08:00:00-12:30:00
13:30:00-16:30:00
09:00:00-17:00:00
18:00:00-20:00:00
09:00:00-17:00:00
18:00:00-20:00:00
08:00:00-17:00:00
18:00:00-20:00:00
09:00:00-17:00:00
18:00:00-20:00:00
现在,我需要做的是每隔 2 行进行分组,所以它看起来像:
08:00:00-12:30:00 13:30:00-16:30:00
09:00:00-17:00:00 18:00:00-20:00:00
09:00:00-17:00:00 18:00:00-20:00:00
08:00:00-17:00:00 18:00:00-20:00:00
09:00:00-17:00:00 18:00:00-20:00:00
这可能吗?感谢您的帮助
编辑:感谢大家的所有答案...我使用了 Shakti 的答案,因为这是我看到的第一个答案,但看起来每个人都非常相似。
【问题讨论】:
标签: php tags while-loop if-statement