我目前有这张表:
<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>   Brand   </th>";
echo "<th>   Product   </th>";
echo "<th>   Availability   </th>";
echo "<th>   Quantity   </th>";
echo "<th>   Price   </th>";
echo "<th>   Description   </th>";
echo "<tr>";
foreach($records as $r) {
echo "<tr>";
}
?>
</table>
答案 0 :(得分:0)
此代码可以帮助您
<table class="table table-bordered ">
<thead>
<tr>
<th> Sl.No </th>
<th> Brand </th>
<th> Product </th>
<th> Availability </th>
<th> Quantity </th>
<th> Price </th>
<th> Description </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>