有人可以告诉我这里我出错的地方,我在使用表格格式的查询中回应一些mysql结果,并且我试图使结果行可点击以便用户可以点击它链接到另一页。
我不明白为什么它不起作用
<?php include 'config.php';
$data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, insurance_date, CURDATE()) AS expire_date FROM supplier_stats ORDER BY expire_date DESC")
or die(mysql_error());
echo "<table class=\"table\" style=\"width:995px; font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
font-size:11px;\" >
<tr>
<td style=\"width:100px;\">ID:</td><td>Company Name:</td><td>Company Reg No:</td><td>Owner:</td><td style=\"width:200px;\">Note:</td><td style=\"width:100px;\">Date:</td><td>Status:</td></tr>";
while($row = mysql_fetch_array( $data )) {
$days = $row['expire_date'];
$when = $days*-1;
$str = $row['expire_date'];
$str2 = substr($str, 1); // "quick brown fox jumps over the lazy dog."
if ($when <= 31){
echo "<a href=\"test.php\"><tr><td style=\"width:100px;\"><p>".$row['id'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_name'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_reg_number'] . "</p></td>";
echo "<td style=\"width:100px;\"><p>".$row['owner'] . "</p></td>";
if ($days > 0) {
echo "<td style=\"width:200px;\"><p><font color=\"red\">Insurance expired!</font>";
echo "<td>";
echo date('d/m/Y',strtotime($row['insurance_date']));
echo"</td>";
if ($when >= 7){ echo "<font color=\"green\">{$row['expire_date']}</font> day(s)!</p></td>"; }
} else {
$when = $days*-1;
echo "<td style=\"width:200px;\"><p>Insurance expires";
if ($when > 1){
if ($when >= 20){
echo " in <font color=\"green\">{$str2}</font> days</font></td>"; }
elseif ($when >= 8){
echo " in <font color=\"orange\">{$str2}</font> days</font></td>"; }
elseif ($when <= 7){
echo " in <font color=\"red\">{$str2}</font> days</font></td>"; }
} elseif ($when >= 1){
echo "<font color=\"red\"> tomorrow!</font></td>";
}
elseif ($when >= 0){
echo "<font color=\"red\"> today!</font></p></td>";
}
echo "<td>";
echo date('d/m/Y',strtotime($row['insurance_date']));
echo"</td>";
}
if ($when >= 20){
echo "<td style=\"width:150px;\"><div class=\"green_light\"></div></td>";
}
elseif ($when >= 8){
echo "<td style=\"width:150px;\"><div class=\"amber_light\"></div></td>";
}
if ($when <= 7){
echo "<td style=\"width:150px;\"><div class=\"red_light\"></div></td>";
}
echo "<tr></a>";
}
}
echo "</table>"; //Close the table in HTML
?>
答案 0 :(得分:1)
您有两种方法可以做到这一点:
使用javascript:
<tr onclick="document.location = 'links.html';">
使用主播
<tr><td><a href="">text</a></td><td><a href="">text</a></td></tr>
我使用以下方式完成了第二项工作:
table tr td a {
display:block;
height:100%;
width:100%;
}
摆脱列之间的死角:
table tr td {
padding-left: 0;
padding-right: 0;
}
这将真正起作用
我应该说谢谢Voyager
答案 1 :(得分:1)
我认为你无法打开
<a> before <tr>
because <table> <tr> <td> must be sequential
您可以使用其他语法:
<td colspan="8"> <a> bla bla bla </a> </td>
答案 2 :(得分:0)
不允许在p
标记
a
标记
将此css代码添加到您的css文件
a {
display: block;
}