php - Query search # going up in ascending order rather then fetching the actual code from database

530

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');

People are also looking for solutions to the problem: php - #laravel 419 error appear submission of any form this problem only on GoDaddy hosting on other hosting app works fine

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.