带有php代码的引导数据表不起作用
我试图使用数据表在带有php代码的引导数据表不起作用,php,bootstrap-4,Php,Bootstrap 4,我试图使用数据表在数据库中使用引导4进行排序和搜索,但它的工作方式与不排序、分页或搜索数据的方式不同。我不知道为什么它不起作用。这是我的密码: <link href="css/addons/datatables.min.css" rel="stylesheet"> <div class="table-responsive"> <table id="datas" class="table table-striped table-bor
数据库中使用引导4
进行排序和搜索,但它的工作方式与不排序、分页或搜索数据的方式不同。我不知道为什么它不起作用。这是我的密码:
<link href="css/addons/datatables.min.css" rel="stylesheet">
<div class="table-responsive">
<table id="datas" class="table table-striped table-bordered" cellspacing="0" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Product</th>
<th>Price</th>
<th>Weight</th>
<th>Image</th>
<th>Type</th>
<th>Type 2</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM products;");
while ($row=mysqli_fetch_array($get)) {
$id=$row['product_id'];
$name=$row['product_name'];
$type2=$row['product_type'];
$weight=$row['weight'];
$price=$row['product_price'];
$type=$row['type'];
$img=$row['img'];
$get1 = mysqli_query($conn," SELECT * FROM money WHERE name='$type' ");
while ($row=mysqli_fetch_assoc($get1)) {
$p=$row['price'];
$newprice = $p*$weight;
}
?>
<tbody>
<td><?php echo $id;?></td>
<td><?php echo $name;?></td>
<td>$<?php echo $newprice;?></td>
<td><?php echo $weight;?> g</td>
<td>
<img src="<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $type;?></td>
<td><?php echo $type2;?></td>
</tbody>
<?php
}
?>
</table>
<script type="text/javascript" src="js/addons/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$('#datas').DataTable();
});
</script>
身份证件
产品
价格
重量
形象
类型
类型2
因为您必须将
放在while循环之外,而且您还忘记添加表原始标记
,所以我已经更新了您的代码
<tbody>
<?php
while ($row=mysqli_fetch_assoc($get1)) {
$p=$row['price'];
$newprice = $p*$weight;
}
?>
<tr>
<td><?php echo $id;?></td>
<td><?php echo $name;?></td>
<td>$<?php echo $newprice;?></td>
<td><?php echo $weight;?> g</td>
<td>
<img src="<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $type;?></td>
<td><?php echo $type2;?></td>
</tr>
<?php } ?>
</tbody>
$
G
“style=”高度:5雷姆;宽度:5雷姆;边界半径:10px;">
您使用了相同的变量,这就是结果可能重叠的原因。请尝试使用两个不同的变量,如$row和$row1。您将
放入while循环,php将其回显。
pic3中的字体错误。请检查src并链接到字体
最后你的代码在这里
<link href="css/addons/datatables.min.css" rel="stylesheet">
<div class="table-responsive">
<table id="datas" class="table table-striped table-bordered" cellspacing="0" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Product</th>
<th>Price</th>
<th>Weight</th>
<th>Image</th>
<th>Type</th>
<th>Type 2</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM products;");
?>
<tbody>
<?php
while ($row=mysqli_fetch_array($get)) {
$id=$row['product_id'];
$name=$row['product_name'];
$type2=$row['product_type'];
$weight=$row['weight'];
$price=$row['product_price'];
$type=$row['type'];
$img=$row['img'];
$get1 = mysqli_query($conn," SELECT * FROM money WHERE name='$type' ");
while ($row = mysqli_fetch_assoc($get1)):
$p=$row['price'];
$newprice = $p*$weight;
?>
<td><?php echo $id;?></td>
<td><?php echo $name;?></td>
<td>$<?php echo $newprice;?></td>
<td><?php echo $weight;?> g</td>
<td>
<img src="<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $type;?></td>
<td><?php echo $type2;?></td>
</tbody>
<?php
endwhile;
?>
</table>
<script type="text/javascript" src="js/addons/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$('#datas').DataTable();
});
</script>
身份证件
产品
价格
重量
形象
类型
类型2
默认情况下,t应该进行排序,但您可以尝试以下$('#示例').dataTable({“ordering”:true});您可能不应该在每一行周围创建一个新的tbody
。?@Emilia,Datatable应用于它。您应该在控制台中有一些丢失字体的错误。请检查04fs可能是对的,它重复body元素,body元素应该只有一次。我从代码中移出tbody,而它毁掉了整个设计