Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 21st, 2005, 8:50 PM   #1
foxcity911
Programmer
 
Join Date: Jun 2005
Location: Queensland
Posts: 37
Rep Power: 0 foxcity911 is on a distinguished road
Multiple IF statements, perhaps?

Hi, what ive done is made a football points table using PHP, that works out games played, percentages, point differences, etc. that is all done properly but now I want to add pictures etc.
I have a drop box with all the team names (Lions, Crows…) that posts to the next page of the currently 2 page program. The team names ($teams on page 2) parse thru and whatever team was selected is printed. What I want is the corresponding team logos to print depending on what team was selected in the drop box (16 teams). The code I originally tried (but obviously didn’t work) was:

 if ($team = "Adelaide Crows") {
print ("<TR><TD>
<IMG SRC='teams\crows.gif'></TD></TR>");

elseif ($team = "Brisbane Lions") {
print ("<TR><TD>
<IMG SRC='teams\lions.gif'></TD></TR>");
}

what happens when I run this is no matter what team I select whether it be lions, crows or another team, it prints the Crows logo, even though it prints the correct team name. What can I do to get around this? Do I need to use multiple if statements? The solution would be greatly appreciated.
foxcity911 is offline   Reply With Quote
Old Jun 21st, 2005, 9:52 PM   #2
TheFalseDragon
Programmer
 
TheFalseDragon's Avatar
 
Join Date: Jun 2005
Location: |\|[][]B |_4|\|D
Posts: 41
Rep Power: 0 TheFalseDragon is on a distinguished road
you could make the $team = the address of the file you are trying to print then give the command
print (<tr><td><img src=teams\$team></td></tr>);

please let me know if the solution works and be warned i'm not sure if it will also i don't know how to get it to put $team in as Adelaide Crows but if you look up the syntax i know its possible. good luck
TheFalseDragon is offline   Reply With Quote
Old Jun 21st, 2005, 10:51 PM   #3
foxcity911
Programmer
 
Join Date: Jun 2005
Location: Queensland
Posts: 37
Rep Power: 0 foxcity911 is on a distinguished road
same problem

hey falsedragon, thanks for the info, but the same problem occurred. i made a variable $crows and made it the img src. i tested it and it printed the logo, so i was ecstatic. then i did added a $lions as the lions logo. so then i did an elseif statement under the crows if statement. tried it out with the lions in the drop menu, and what happened? the same thing again. it is somehting to do with the if statement. there must be a way to include both and all images in one statement. perhaps an or function if it exists.
thanks anyway. regards
foxcity911 is offline   Reply With Quote
Old Jun 21st, 2005, 11:39 PM   #4
TheFalseDragon
Programmer
 
TheFalseDragon's Avatar
 
Join Date: Jun 2005
Location: |\|[][]B |_4|\|D
Posts: 41
Rep Power: 0 TheFalseDragon is on a distinguished road
do you have msn so i could try to help you there?

i am da_devestator2001@yahoo.com (msn)

add me and i'll help you fix it. plus it will be just 2 lines long

Last edited by TheFalseDragon; Jun 21st, 2005 at 11:40 PM. Reason: Adding my MSN
TheFalseDragon is offline   Reply With Quote
Old Jun 21st, 2005, 11:52 PM   #5
foxcity911
Programmer
 
Join Date: Jun 2005
Location: Queensland
Posts: 37
Rep Power: 0 foxcity911 is on a distinguished road
Lightbulb switch statements?

i just came out of my brain death and i thought "maybe a switch statement would work". do u think it could work? heres what ive tried.
switch ($team){
 case ($team = "Adelaide Crows"):
 echo ("<TR><TD><IMG SRC = 'teams\crows.gif'></TR></TD>");
im fairly ignorant when it comes to switch statements though. how would i add a second case in there. eg i would want it to look like:

switch ($team){
 case ($team = "Adelaide Crows"):
 echo ("<TR><TD><IMG SRC = 'teams\crows.gif'></TR></TD>");
break: 
case ($team = "Brisbane Lions"):
 echo ("<TR><TD><IMG SRC = 'teams\lions.gif'></TR></TD>");
etc.

is there a way i can make this switch statement work like this? any input from anyone is very welcome.
thanks
foxcity911 is offline   Reply With Quote
Old Jun 22nd, 2005, 12:03 AM   #6
foxcity911
Programmer
 
Join Date: Jun 2005
Location: Queensland
Posts: 37
Rep Power: 0 foxcity911 is on a distinguished road
Thumbs up Major Breakthrough

hi falsedragon, MAJOR BREAKTHRU. as i said before i was trying switch statements. IT WORKED. heres a snippet of a successful code:
switch ($team){
 case ($team="Adelaide Crows"):
 echo ("<TR><TD><IMG SRC = 'teams\crows.gif'></TR></TD>");
break; 
case ($team="Brisbane Lions"):
 echo ("<TR><TD><IMG SRC = 'teams\lions.gif'></TR></TD>");
}

it actually prints the team logo that corresponds with the team name!
thanks for your help!
foxcity911 is offline   Reply With Quote
Old Jun 22nd, 2005, 12:04 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
The problem in the original code was that the if block was missing a closing }. Watch out for these things.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 22nd, 2005, 3:33 PM   #8
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
switch ($team){
 case ($team="Adelaide Crows")
look twice at that, it'll always be true. you have to compare $team to "Adalaide Crows"

while(a=10){ .... }
will run forever.

while(a==10){ .... }
will only run when a is equal to 10.
-Dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC