Echo Out Mysql Into A Html Table?
I need some help on how to echo out my mysql data into a html table. I'm trying to put in the relevant table tags where necessary but I must be doing it wrong as its not looking ho
Solution 1:
You need more or less somethin like this:
<?phpinclude'config.php';
$data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date FROM supplier_stats")
ordie(mysql_error());
echo"<table class=\"table\" style=\"width:900px; font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
font-size:11px; color:#96969;\" >";
while($row = mysql_fetch_array( $data )) {
$days = $row['expire_date'] -1;
echo"<tr><td><p>".$row['id'] . "</p></td>";
echo"<td><p>".$row['company_name'] . "</p></td>";
if ($days > 0) {
echo"<td><p>Insurance expires in <font color=\"red\">{$row['expire_date']} day(s)!</font></p></td>";
} else {
$when = $days*-1;
echo"<td><p>Insurance expires";
if ($when > 1){
echo" in {$when} days</p></td>";
}
if ($when >= 8){
echo" <div class=\"green_light\"></div>";
}
if ($when <= 7){
echo" <div class=\"red_light\"></div>";
} elseif ($when ===1) {
echo" tomorrow</p></td>";
} elseif ($when == 0) {
echo" today</p></td>";
}
}
echo"<tr>";
}
echo"</table>"; //Close the table in HTML?>
Solution 2:
you've closed after first that is why you are getting output like this..remove from:
echo "<tr><td><p>".$info['id'] . "</p></td></tr>";
above line...and close after while loop ends..
Solution 3:
<table><tr><td>Id</td><td>Name</td><td>Number</td><td>Note</td><td>Alert</td></tr><?php$sql = mysql_query("your query");
$i = 0;
while ($info = mysql_fetch_array($data))
{
$i++
?><td><?phpecho$i; ?></td><td><?phpecho$info['name']; ?></td><td><?phpecho$info['number']; ?></td><td><?phpecho$info['note']; ?></td><td><?phpecho$info['alert']; ?></td></tr><?php
}
?></table>
Post a Comment for "Echo Out Mysql Into A Html Table?"