如何在表格中回显数据

时间:2017-02-27 20:14:19

标签: php html

我有这个代码从DB获取数据然后回显它。如何使代码回显数据如下表所示: enter image description here

代码:

$username = $_POST['username'];

$connnn = mysqli_connect("localhost", "root", "0598985166sallam", "project");
$sqllll = "SELECT value, status,no FROM bill WHERE username = '$username'";
$resulttt = $connnn->query($sqllll);

if ($resulttt->num_rows > 0) {
    while ($row = $resulttt->fetch_assoc()) {
        echo "<tr> <td>$row[no]</td> <td>$row[value] </td> <td> $row[status]</td></tr>";
    }
}

2 个答案:

答案 0 :(得分:0)

你可以使用字符串连接

  echo "<tr> <td>" . $row['no'] .
     "</td> <td>" . $row['value'] . 
      "</td> <td>".  $row['status'] . "</td></tr> ";    

答案 1 :(得分:0)

如果我理解你的问题,那么我认为你找到了这个解决方案:

$username = $_POST['username'];
$connnn   = mysqli_connect("localhost", "root", "0598985166sallam" ,     
"project");
$sqllll   = "SELECT value, status,no FROM bill WHERE username = '$username'";
$resulttt = $connnn->query($sqllll);
if ($resulttt->num_rows > 0){
   echo "<table class='anyClass'>";
   echo "<tr>
             <th>Bill Num</th>
             <th>Bill Val</th>
             <th>Bill stuts</th>
        </tr>";
   while($row = $resulttt->fetch_assoc())
      echo "<tr> 
              <td>".$row[no]."</td> 
              <td>".$row[value]."</td> 
              <td>".$row[status]."</td>     
          </tr>";
  echo "</table>";
}
相关问题