更新:我得到的警告是''警告:mysqli_fetch_array()期望参数1是mysqli_result,load_price.php中的布尔值15在第15行中给出''
我正在制作一个电子商务网站,我想下拉菜单,一个用于选择颜色(作品),一个用于价格(不起作用)
阅读了对价格不起作用的价格进行排序的相同步骤
菜单链接到外部PHP脚本文件,必须很简单外部文件:
<?php include "db/connect.php";?>
<?php
$output = '';
if(isset($_POST["price"]))
{
if($_POST["price_id"] != '')
{
$sql = "SELECT * FROM 'clothing' ORDER BY 'price' '".$_POST["price_id"]."'";
}
else
{
$sql = "SELECT * FROM clothing";
}
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= "
<div class=items>
<a href=viewitem.php?itemid=".$row['itemid'].">
<div class='effect'>
<img class='image' src=clothing/" . $row["firstimage"]. " class=img-responsive style=width:100% alt=Image>
<img class='image hover' src=clothing/" . $row["secimage"]. " class=img-responsive style=width:100% alt=Image>
</div>
<div class=item-names>" . $row["productname"]. "</div>
<div class=item-prices>$" . $row["price"]. "</div>
</div>
";
}
echo $output;
}
?>
HTML file
<script>
$(document).ready(function(){
$('#price').change(function(){
var price_id = $(this).val();
$.ajax({
url:"load_price.php",
method:"POST",
data:{price_id},
success:function(data){
$('#show_product').html(data);
}
});
});
});
</script>
<?php
function fill_price($conn)
{
$output = '';
$sql = "SELECT * FROM price";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= '<option value="'.$row["price_id"].'">'.$row["price"].'</option>';
}
return $output;
}
//load_data_select.php
function fill_color($conn)
{
$output = '';
$sql = "SELECT * FROM color";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= '<option value="'.$row["color_id"].'">'.$row["color"].'</option>';
}
return $output;
}
function fill_product($conn)
{
$output = '';
$sql = "SELECT * FROM clothing";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= "
";
}
return $output;
}
?>
<select name="price" id="price">
<option value="">Show All</option>
<?php echo fill_price($conn); ?>
</select>
<select name="color" id="color">
<option value="">Show All Colours</option>
<?php echo fill_color($conn); ?>
</select>
<br /><br />
<div id="show_product">
<?php echo fill_product($conn);?>
</div>
</div>
语法错误。
因此,只需在单引号中添加classes
。
<?php
$output = '';
while($row = mysqli_fetch_array($result))
{
$output .= "
<div class='item-names'>" . $row["productname"]. "</div>
<div class='item-prices'>$" . $row["price"]. "</div>
";
}
echo $output;
?>
图像标签(示例)
<td>
<img class='product-image' src='http://localhost/product_loader/uploads/". $row["product_image_path"]. "'>
</td>
修复您的图像标签:
<img class='image img-responsive' src='clothing/". $row["firstimage"]. "' style='width:100%;' alt='Image'>