David Nelson Posted June 10, 2008 Share Posted June 10, 2008 Well, I have this snippet of code I wrote to look at what somebody has typed into an input box and yield different results depending on what they typed. I have the following file included on my page, oddly enough, it does nothing.. It doesn't change out the specified variables if they're inputted. Even more weird, it was working for me when I was only using 2 different 'if' functions, now that I have 5 I'm not sure what happened. :-\ No errors come up either. Thanks! I appreciate it. <?php //THIS FILE IS FOR THE BAND PIC IN THE SIDEBAR //copy and paste entries to make more, just follow the patterns //you can copy any entry except for the last one to use as a template //for more, also, you cannot add these below the last entry, as that //makes it no longer the last entry. //entry 1 - if ivete sangalo is typed, this will apply. if ($artist == "ivete sangalo") { echo ' <img src=\"link to band image\">'; } //entry 2 - if rammstein is typed, this will apply. if ($artist == "rammstein") { echo ' <img src=\"link to band image\">'; } //entry 3 - if nickelback is typed, this will apply. if ($artist == "nickelback") { echo ' <img src=\"link to band image\">'; } //entry 4 - if 3 doors down is typed, this will apply. if ($artist == "3 doors down") { echo ' <img src=\"link to band image\">'; } //entry 5 - if sorriso maroto is typed, this will apply, because this is the last entry //of the list, there differences in the code, so to produce more artists to modify, never //copy and paste the last one as a template. Use any of the ones above this instead. if ($artist == "sorriso maroto") { echo ' <img src=\"link to band image\">'; }else{ include("bandpic.php?artist=$altartist"); } ?> Link to comment https://forums.phpfreaks.com/topic/109520-solved-weird-issue-with-quotifquot-quotelsequot-function/ Share on other sites More sharing options...
btherl Posted June 10, 2008 Share Posted June 10, 2008 How is it supposed to work? Is the "else" supposed to apply to all "if" or just the last one? For a start with the debugging, I would add this line at the top: print "artist is $artist<br>"; That will at least tell you if $artist is set. To assist with debugging, can you give us a few sets of input and output. Eg "I type '3 doors down' as the artist, and I get a blank page" Link to comment https://forums.phpfreaks.com/topic/109520-solved-weird-issue-with-quotifquot-quotelsequot-function/#findComment-561790 Share on other sites More sharing options...
David Nelson Posted June 10, 2008 Author Share Posted June 10, 2008 Else should apply to all. Artist is set, your test does what it should. If I type three doors down as the artist, it returns the ELSE include function as though it did not see that 3 doors down was one of the variables I wanted to be changed under 'if' Link to comment https://forums.phpfreaks.com/topic/109520-solved-weird-issue-with-quotifquot-quotelsequot-function/#findComment-561802 Share on other sites More sharing options...
btherl Posted June 10, 2008 Share Posted June 10, 2008 Aha. Then you should write it like this: //entry 1 - if ivete sangalo is typed, this will apply. if ($artist == "ivete sangalo") { echo ' <img src=\"link to band image\">'; } //entry 2 - if rammstein is typed, this will apply. elseif ($artist == "rammstein") { echo ' <img src=\"link to band image\">'; } The difference is the "elseif" instead of "if". If you miss that out, then the final else will only apply to the final test. You should find with your current code that the final "else" is being executed for all cases except when $artist = "sorriso maroto" elseif should be added for all "if" except the first one. The general structure is: if (...) { } elseif (...) { } elseif (...) { } else { } Link to comment https://forums.phpfreaks.com/topic/109520-solved-weird-issue-with-quotifquot-quotelsequot-function/#findComment-561816 Share on other sites More sharing options...
David Nelson Posted June 10, 2008 Author Share Posted June 10, 2008 Great, that worked. Thanks a bunch I appreciate it. David Link to comment https://forums.phpfreaks.com/topic/109520-solved-weird-issue-with-quotifquot-quotelsequot-function/#findComment-561823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.