php - Query search # going up in ascending order rather then fetching the actual code from database
I have a query fetching product ID from the database, then base on the ID #, I have a switch statement that gets the image for the product. All works fine and at the end of the switch I have a default case where it would just print out an image that says "no image available".
Here is part of the code for imagequery.php
<?php
if($image = mysqli_fetch_assoc($imagequery))
{
switch($image['product_code'])
{
case 0:
echo '<th><img src="Images/pencil.jpg">';
break;
case 1:
echo '<th><img src="Images/pen.jpg">';
break;
case 2:
echo '<th><img src="Images/marker.png">';
break;
case 3:
echo '<th><img src="Images/clipper.png">';
break;
case 4:
echo '<th><img src="Images/paper.png">';
break;
default:
echo '<th><img src="Images/noimage.jpg">';
break;
}
}
Edit1: After doing more recommended echo checks, turns out the $image['imagequery'] is going in ascending order and I'm not sure why. My code to get $imagequery is this.
$results = "SELECT product_code FROM products WHERE product_desc='Office Materials'";
$imagequery = mysqli_query($mysqli, $results);
include('imagequery.php');