将mysql回显到html表中?
问题描述:
我需要一些关于如何将我的mysql数据回显到html表中的帮助。我试图在必要时插入相关的表格标签,但我必须做错了,因为它看起来不是我想要的。
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 how I want it.
这是我得到的:
ID Name Number Note Alert
1
2
Nick Nick insurance insurance alert alert
以下是我希望它的样子:
Here is how I want it to look:
ID Name Number Note Alert
1 Nick Insurance Alert
2 Nick Insurance Alert
这是我的代码,有人可以告诉我在哪里需要放置我的表格标签以获得所需的结果:
Here is my code, can someone please show me where I need to put my table tags to get the desired result:
<?php
include 'config.php';
$data = mysql_query("SELECT * FROM supplier_stats") or die(mysql_error());
echo "<table class=\"table\" style=\"width:900px; font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
font-size:11px; color:#96969;\" >";
while ($info = mysql_fetch_array($data))
{
echo "<tr><td><p>" . $info['id'] . "</p></td></tr>";
}
?>
<?php
include 'config.php';
$data = mysql_query("SELECT * FROM supplier_stats") or die(mysql_error());
while ($info = mysql_fetch_array($data))
{
echo "<td><p>" . $info['company_name'] . "</p></td>";
}
?>
<?php
include 'config.php';
$data = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
FROM supplier_stats") or die(mysql_error()); ?>
<?php
include 'config.php';
$result = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
FROM supplier_stats") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$days = $row['expire_date'] - 1;
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>";
}
}
}
?>
<?php
include 'config.php';
$result = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
FROM supplier_stats") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$days = $row['expire_date'] - 1;
if ($days > 8)
{
echo "a is bigger than b";
}
}
echo "</table>"; //Close the table in HTML
?>
答
你或多或少需要这样的东西:
You need more or less somethin like this:
<?php include 'config.php';
$data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date FROM supplier_stats")
or die(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
?>