将记录从sql提取到表

时间:2018-04-12 10:39:12

标签: php mysql sql

我需要从表中的sql显示我的记录。在sql中保存记录 - 日期,小时,主题。我有问题,我将每个记录保存到$记录,我只需要例如第二行主题,日期,小时显示到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'");

并且有php插入的HTML

<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>

2 个答案:

答案 0 :(得分:0)

使用SQL查询。

请提供更多信息,以便人们可以提供更好的答案,否则您将收到此类答案。

(用户提问在发布这个时髦的回复后更新了他们的问题。)

答案 1 :(得分:0)

$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");