gpt4 book ai didi

php - 从sql中提取记录到表中

转载 作者:行者123 更新时间:2023-11-29 17:46:18 25 4
gpt4 key购买 nike

我需要在表中显示 sql 中的记录。在 sql 中保存的记录包括日期、时间、主题。我有一个问题,我将每个记录保存到 $record 中,并且我只需要例如第二行的主题、日期、小时即可显示到 10:00。我不知道行数,每天都可能是其他的。检查代码你就会明白。感谢您的帮助。

$time10 = mysql_query("SELECT * FROM record WHERE slotDate = '$date' AND slotTime = '10:00'");
$time12 = mysql_query("SELECT * FROM record WHERE slotDate = '$date' AND slotTime = '12:00'");

并且有 html 和 php 插入

<tr><!--FIRST RECORD OF 10:00-->
<td>
while($record = MySQL_Fetch_Row($time10)):
echo $record[0]; echo "<p>";
echo $record[1]; echo "<p>";
echo $record[3];
</td>
</tr>

<tr><!--SECOND RECORD OF 10:00-->
<td> There i need 2nd row
</td>
</tr>

<tr><!--THIRD RECORD OF 12:00-->
<td> There i need for example 3rd row from TIME 12:00
</td>
</tr>

最佳答案

$time10 = mysql_query("SELECT * FROM record WHERE slotDate = '$date' AND slotTime = '10:00'");
echo '<table>';
echo '<tr><th>Date</th><th>Time</th><th>Subject</th></tr>';
while ($record = mysql_fetch_row($time10)) {
echo '<tr><td>'.$record[0].</td><td>.$record[1].</td><td>.$record[2].'</td></tr>';
}
echo '</table>';

它将所有记录打印为表格,其中时间为 10:00

如果您只需要选择第二行,请尝试使用 LIMIT first_row count_rows

$time10 = mysql_query("SELECT * FROM record WHERE slotDate = '$date' AND slotTime = '10:00' LIMIT 1, 1");

关于php - 从sql中提取记录到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49794403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com