Reputation: 45
Can someone please show me where i am going wrong with this, i am echoing out some mysql results in a query using a table format, and i am trying to make the row of results clickable so a user can click on it an link to another page.
i dont understand why its not working
<?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
?>
Upvotes: 0
Views: 80
Reputation: 5396
You have two ways to do this:
Using javascript:
<tr onclick="document.location = 'links.html';">
Using anchors:
<tr><td><a href="">text</a></td><td><a href="">text</a></td></tr>
I made the second work using:
table tr td a {
display:block;
height:100%;
width:100%;
}
To get rid of the dead space between columns:
table tr td {
padding-left: 0;
padding-right: 0;
}
This will work really work
I should say thanks Voyager
Upvotes: 1
Reputation: 809
I think you cannot open
<a> before <tr>
because <table> <tr> <td> must be sequential
you can use other syntax like :
<td colspan="8"> <a> bla bla bla </a> </td>
Upvotes: 0
Reputation: 2290
it is not allowed to use the p
tag within an a
tag
add this css-code to your css file
a {
display: block;
}
Upvotes: 0