简体   繁体   English

用表在网站上显示MySQL数据的最简单方法?

[英]Simplest way to display MySQL data on a website with a table?

I am trying to display data from from a database in a table, with one column for the names and another for the values, instead of the rudimentary layout it currently has: 我试图在表中显示来自数据库的数据,其中一列用于名称,另一列用于值,而不是它当前具有的基本布局:

while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  echo "{$row['date']}  <br> ".
     "--------------------------------<br>".
     "Temperature :{$row['temperature']}  <br> ".
     "Luminosite : {$row['luminosite']} <br> ".
     "Humidite : {$row['humidite']} <br> ".
     "--------------------------------<br>";
}

I am very much a novice in all things php so any suggestions are welcome. 我是所有php的新手,因此欢迎您提出任何建议。

Try Using below code 尝试使用以下代码

    echo "<table>
          <tr>
          <th>Date</th> 
          <th>Name</th>
          <th>luminosite</th>
          <th>humidite</th>
          </tr>";

    while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
    echo "<tr>
          <td>".$row['date']."</td>
          <td>".$row['temperature']."</td>
          <td>".$row['luminosite']."</td>
          <td>".$row['humidite']."</td>
          </tr>";
    }
    echo "</table>";

Try this code 试试这个代码

<table>
  <tr>
    <td>Date</td><td>Temperature</td><td>Luminosite</td><td>Humidite</td>
  </tr>
  <?php
    while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
      echo "<tr>
        <td>$row['date']</td>
        <td>$row['temperature']</td>
        <td>$row['luminosite']</td>
        <td>$row['humidite']</td>
      </tr>";
    }
  ?>
</table>

Try to use this code 尝试使用此代码

<html>
<head>
    <title>Test</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body>
    <div>
        <div class="row">
            <div class="table-responsive">
                <table class="table table-striped table-hover" id="my_table">
                    <thead>
                        <tr>                                                   
                            <th>Temperature</th>
                            <th>Luminosite</th>
                            <th>Humidite</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
                        $query = "select * from table";

                        $conn  = mysqli_connect("localhost", "root", "password", "ecom");

                        $data  = mysqli_query($conn, $query);

                        while ($row = mysqli_fetch_array($data)) 
                        {

                            $temperature = $row['temperature'];
                            $luminosite  = $row['luminosite'];
                            $humidite    = $row['humidite'];

                        echo "<tr><td>$temperature</td><td>$luminosite</td><td>$humidite</td></tr>";    


                        }
                    ; ?>
                </tbody>
                </table>
            </div>
        </div>
    </div>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>

Do not use MySQL. 不要使用MySQL。

<table>
  <tr>
    <?php 
      while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
    ?>
      <td>
        <?php echo "{$row['date']};?>
      <td>
      <td>
        <?php echo "{$row['temperature']};?>
      <td>
      <!-- other fiels -->
    <?php
      }
    ?>
  </tr>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM