Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

different images for different variables

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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
fspilot
New php-forum User
New php-forum User
 
Posts: 26
Joined: Fri Jun 27, 2003 11:51 am
Location: Bath UK

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']];?>" />
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada

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";
}
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

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.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

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?
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron