Help with mysql converting results

Ok, I am new to php and mysql so please bare with me.

This is what I’m wanting to do but can not get it to work. I have a mysql table that will return the results of the database into a table. There are 5 data fields, “id”, “type”, “name”, “date” and “serialnumber”.

The “type” field is only two numbers… “01” or “02” or “03” what I want it to do is as it pulls that rows data from the database display picture 1 if the “type” is “01”, or display picture 2 if the type is “02” or display picture 3 if the “type” is “03” and still display the other results… make sense?

Could someone help?!

Thanks in advance


Well, you seem to have forgotten to state what the problem is that occurs. What is it (not) doing that it should(n’t) do?

Not completely sure where or what your stuck on… Is it an SQL/Database problem?

The one problem I can see (or think I see) that you are having you can resolve by using a SWITCH command.


/// Some code before this point

switch ($type) {

case (‘01’):
$img = “/path/to/image1.jpg”;
case (‘02’):
$img = “/path/to/image2.jpg”;
case (‘03’):
$img = “/path/to/image3.jpg”;
case (‘04’):
$img = “/path/to/image4.jpg”;
$img = “/path/to/default.jpg”;

// remaining code

Sponsor our Newsletter | Privacy Policy | Terms of Service