PHP获取数据并插入到html表中

时间:2016-07-28 15:29:13

标签: php

SELECT date, DAYNAME(date) as day , time FROM booking WHERE date BETWEEN CURDATE() AND CURDATE() + INTERVAL 7 DAY

查询后,将返回日期结果及其具体时间。 query result

并将日期填充到html表中。

然而,真正的问题是,当结果返回多于1个结果时,它将根据数字或结果填充表。 example

这是我用来遍历结果的PHP代码,

function checkHari() {

    $sql = "SELECT date, DAYNAME(date) as Hari , time FROM booking WHERE date BETWEEN CURDATE() AND CURDATE() + INTERVAL 7 DAY";
    $results = mysql_query($sql);
    $num_rows = mysql_num_rows($results);

    return $results;
}

$check_hari = checkHari();


while ($row = mysql_fetch_assoc($check_hari)) {
 <?php if( $hari = 'Wednesday' ) { ?>
 <tr>
 <td>Wednesday</td>
 <?php if ($time >= 8 && $time < 10) {
  echo '<td id="Wednesday0810" class="blacked"><small>Booked</small></td>';
  } else {
  echo '<td></td>';
  } ?>
 <?php if ($time >= 10 && $time < 12) {
  echo '<td id="Wednesday1012" class="blacked"><small>Booked</small></td>';
  } else {
  echo '<td></td>';
  } ?>
 <?php if ($time >= 12 && $time < 14) {
  echo '<td id="Wednesday1214" class="blacked"><small>Booked</small></td>';
  } else {
  echo '<td></td>';
  } ?>
 <?php if ($time >= 14 && $time < 16) {
  echo '<td id="Wednesday1416" class="blacked"><small>Booked</small></td>';
  } else {
  echo '<td></td>';
  } ?>
 <?php if ($time >= 16 && $time < 18) {
  echo '<td id="Wednesday1618" class="blacked"><small>Booked</small></td>';
  } else {
  echo '<td></td>';
  } ?>
</tr>

0 个答案:

没有答案