different images for different variables

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

fspilot
New php-forum User
New php-forum User
Posts: 26
Joined: Fri Jun 27, 2003 11:51 am
Location: Bath UK
Contact:

different images for different variables

Postby fspilot » Fri Jun 27, 2003 11:54 am

I have a variable called Rank and i want the script to show a different image depending on what "Rank" is.

Im quite new to PHP and dont have a clue how to do this or even if i can do this.

Does anybody know if i can??

any help would be most appreciated.

Regards
Dan

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Fri Jun 27, 2003 12:40 pm

here is a example:


$myarray["junior"] = "images/junior.jpg";
$myarray["senior"] = "images/senior.jpg";


then in your script that generates the output:

<img src="<?php echo $myarray[$_GET['userType']];?>" />

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Mon Jun 30, 2003 8:30 pm

Or you could do this..

Code: Select all

switch ($rank) {
       case: 1
            $image = "images/1.gif";
            break;
       case: 2
            $image = "images/2.gif";
            break;
       default:
             $image = "No ranking";
}

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Tue Jul 01, 2003 1:00 am

Using the array makes it much more flexable. All it requires is an entry in a database. The latter forces you to hardcode a case statement. If you later choose to add several different levels you would have to go back and code it.

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Tue Jul 01, 2003 6:47 am

I guess I imagined a list of data with the rank of something like "most visited" or something. What are you using the rank for fspilot?


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron