按日期更改PHP数据表中的行颜色

时间:2014-12-12 07:09:36

标签: javascript php html mysql

Today : <?php echo date("m/d/Y"); ?>
<ph>ISSUED BOOKS | DUE BOOKS</ph>
    <table border="1" cellpadding="3" cellspacing="0" id="tblissued">
      <tr bgcolor="#CCCCCC">
        <th height="39">id</th>
        <th>Officer</th>
        <th>Member_ID</th>
        <th>Book_ID</th>
        <th>Issued_date</th>
        <th>Due_date</th>
        <th>Remarks</th>
      </tr>
      <?php do { ?>
        <tr bgcolor="#FFFFFF">
          <td height="33"><?php echo $row_rsissuedbooks['id']; ?></td>
          <td><?php echo $row_rsissuedbooks['Officer']; ?></td>
          <td><?php echo $row_rsissuedbooks['Member_ID']; ?></td>
          <td><?php echo $row_rsissuedbooks['Book_ID']; ?></td>
          <td><?php echo $row_rsissuedbooks['Issued_date']; ?></td>
          <td><?php echo $row_rsissuedbooks['Due_date']; ?></td>
          <td><?php echo $row_rsissuedbooks['Remarks']; ?></td>
        </tr>
        <?php } while ($row_rsissuedbooks = mysql_fetch_assoc($rsissuedbooks)); ?>
    </table>

如果due_date大于今天(代码中的第1行,我想为行Due_date着色) 我不懂英文.. 对不起,我希望你能理解..

2 个答案:

答案 0 :(得分:0)

这样的事情会起作用。

  <?php do {
  $style = "";
  if ($row_rsissuedbooks['Due_date'] > date("m/d/Y")){
    $style = "style='background:#FF0000;'";
  }
  ?>
    <tr bgcolor="#FFFFFF">
      <td height="33"><?php echo $row_rsissuedbooks['id']; ?></td>
      <td><?php echo $row_rsissuedbooks['Officer']; ?></td>
      <td><?php echo $row_rsissuedbooks['Member_ID']; ?></td>
      <td><?php echo $row_rsissuedbooks['Book_ID']; ?></td>
      <td><?php echo $row_rsissuedbooks['Issued_date']; ?></td>
      <td <?php echo $style;?>><?php echo $row_rsissuedbooks['Due_date']; ?></td>
      <td><?php echo $row_rsissuedbooks['Remarks']; ?></td>
    </tr>
    <?php } while ($row_rsissuedbooks = mysql_fetch_assoc($rsissuedbooks)); ?>

答案 1 :(得分:0)

试试这个:

<td><?php echo $row_rsissuedbooks['Issued_date']; ?></td>
<?php
    echo "<td";
    if(strtotime($row_rsissuedbooks['Due_date'])>time())
    {
        echo " style=\"background-color:#00FF00\"";
    }
    echo ">".$row_rsissuedbooks['Due_date']."</td>";
?>
<td><?php echo $row_rsissuedbooks['Remarks']; ?></td>