在PHP中显示S3DB数据库 [英] Showing S3DB Database in PHP

查看:121
本文介绍了在PHP中显示S3DB数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有这张表:

I currently have this 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代码。

I need help in viewing the database table for each column in the PHP table. I am only using Xampp and each PHP file and s3db database is in there. Can someone please guide me through the PHP code that I need to make it work.

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

So far i tried this:

<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>


推荐答案

此代码可以帮助您

<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>

这篇关于在PHP中显示S3DB数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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