我有数据库行的渲染
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['tex1'] . '</td>';
echo '<td>' . $row['tex2'] . '</td>';
echo '<td>' . $row['tex3'] . '</td>';
echo '<td>' . $row['tex4'] . '</td>';
echo '<td>' . $row['tex5'] . '</td>';
echo '<td>' . $row['tex6'] . '</td>';
echo '<td>' . $row['tex7'] . '</td>';
echo '<td>' . $row['tex8'] . '</td>';
echo '<td>' . $row['tex9'] . '</td>';
echo '<td>' . $row['tex10'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
而且在tex1中是一个日期,我的问题是对于tr的类,当tex2为空并且tex1的日期早于30天,tr为类,则手动插入了tex1的日期,我该怎么办在此基础上改变阶级?
最佳答案
我不确定我是否了解您的要求,但是会给您一个机会。只要满足日期早于30天(tex1)或名字为空(tex2)的条件,您就想向中添加类(“红色”)。
echo "<table border='1' cellpadding='10'>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
// I assume since you're just printing it out, the date is a String
// So first convert it to a timestamp
$date = strtotime($row['tex1']);
// Determine the difference, I'm doing it this way to make it easy for you to understand
$days = 60*60*24*30; // 30 days
if (empty($row['tex2']) || time()-$date > $days) {
echo '<tr>';
} else {
echo '<tr class="red">';
}
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['tex1'] . '</td>';
echo '<td>' . $row['tex2'] . '</td>';
echo '<td>' . $row['tex3'] . '</td>';
echo '<td>' . $row['tex4'] . '</td>';
echo '<td>' . $row['tex5'] . '</td>';
echo '<td>' . $row['tex6'] . '</td>';
echo '<td>' . $row['tex7'] . '</td>';
echo '<td>' . $row['tex8'] . '</td>';
echo '<td>' . $row['tex9'] . '</td>';
echo '<td>' . $row['tex10'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";