UPDATE: the warning i get is '' Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in load_price.php on line 15 ''
I am making an e-commerce site, and I am trying to have to dropdown menus, one for selecting colour (works) and one for price (does not work)
After reading the same step for sorting the prices it does not work
The menus are linked to an external php script file, it must be something simple External file:
<?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>