将mysql回显到html表中? [英] Echo out mysql into a html table?

查看:488
本文介绍了将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
    ?>

这篇关于将mysql回显到html表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆