用PHP显示S3DB数据库

时间:2017-05-17 15:52:54

标签: php html database sqlite html-table

我目前有这张表:

<table class="table table-bordered table-edited">
<thead>
  <tr>
    <th>Image</th>
    <th name="brand">Brand</th>
    <th name="product">Product</th>
    <th name="availability">Availability</th>
    <th name="quantity">Quantity</th>
    <th name="price">Price</th>
    <th name="description">Description</th>
  </tr>
</thead>

我需要帮助查看PHP表中每列的数据库表。我只使用Xampp,每个PHP文件和s3db数据库都在那里。有人可以指导我完成我需要的PHP代码。

到目前为止,我试过这个:

<table class="table table-bordered table-edited">
  <?php

    $db = new PDO('sqlite:Products.s3db');

    echo "<tr>";
    echo "<th> &nbsp Brand &nbsp </th>";
    echo "<th> &nbsp Product &nbsp </th>";
    echo "<th> &nbsp Availability &nbsp </th>";
    echo "<th> &nbsp Quantity &nbsp </th>";
    echo "<th> &nbsp Price &nbsp </th>";
    echo "<th> &nbsp Description &nbsp </th>";

    echo "<tr>";

    foreach($records as $r) {
        echo "<tr>";
    }

?>
</table>

1 个答案:

答案 0 :(得分:0)

此代码可以帮助您

<table class="table table-bordered ">
<thead>
<tr>
<th> &nbsp; Sl.No &nbsp; </th>
<th> &nbsp; Brand &nbsp; </th>
<th> &nbsp; Product &nbsp; </th>
<th> &nbsp; Availability &nbsp; </th>
<th> &nbsp; Quantity &nbsp; </th>
<th> &nbsp; Price &nbsp; </th>
<th> &nbsp; Description &nbsp; </th>    
<tr>
</thead>
<tbody>
    <?php 
  $db = new PDO('sqlite:Products.s3db');

  $sql = "SELECT * FROM `tbl_name` ";

  $result = $db->query($sql);
      if($result){
        while($row = $result->fetch(PDO::FETCH_ASSOC)){

            echo '<tr>
                    <td>'.$i++.'</td>
                    <td>'.$row['brand'].'</td>
                    <td>'.$row['product'].'</td>
                    <td>'.$row['availability'].'</td>
                    <td>'.$row['quantity'].'</td>
                    <td>'.$row['price'].'</td>
                    <td>'.$row['description'].'</td>
                  </tr>';
        }

    ?>
</tbody>
</table>