此刻我正在使用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