此刻我正在使用WHERE循环来显示数据库中的2列信息。下面的代码:将WHILE循环结果分组
$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
这可能吗?感谢您的帮助
编辑:感谢所有的答案,每个人......我用沙克蒂的答案,因为这是我看到的第一个,但看起来它的每个人都非常相似。
+1为解决方案。 -1为可怕的,不一致的格式。 – 2011-03-31 16:27:11
@Tom:同意你 – 2011-03-31 16:32:15
然而,你并没有修正它在你的编辑。 – 2011-03-31 16:40:51