Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing text with images

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
I have approx 12 fields being returned to a user from a table within a MySQL database.

One of the tables will always contain one of three possible values (Sold, Rejected or Outstanding) within the status field. When I return all the information to the user, I would love to be able to replace the status field with an image. So if it was marked as Sold, a tick would be there, or an X for Rejected, for example.

I imagine I need to use an array or something but I've no idea and was hoping maybe one of you genii could help?
 
You could just use switch structure:
Code:
switch ($row['status'])
{
  case "Sold":
    echo '<img src="sold.gif" alt="Sold" />';
    break;
  case "Rejected":
    echo '<img src="rejected.gif" alt="Rejected" />';
    break;
  case "Outstanding":
    echo '<img src="outstanding.gif" alt="Outstanding" />';
    break;
}
Of course you may have to tweak the code to make it work for you.
 
You're brilliant :)

I'm relatively new to using PHP (up until now I only really availed of the include function) and did not know how to pass the Status into a switch :)

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top