adamjones Posted October 26, 2008 Share Posted October 26, 2008 Ok. So I have this code. The idea of it is to change the background of my website, for special occasions; <?php mysql_connect("localhost", "wowdream_dreams", "pass") or die(mysql_error()); mysql_select_db("wowdream_dreams") or die(mysql_error()); $result = mysql_query("SELECT * FROM theme") or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { if($row['theme'] == christmas) { echo"images/christmas_bg.gif"; } if($row['theme'] == easter) { echo"images/easter_bg.gif"; } if($row['theme'] == halloween) { echo"images/halloween_bg.gif"; } if($row['theme'] == valentines) { echo"images/valentines_bg.gif"; } if($row['theme'] == newyear) { echo"images/newyear_bg.gif"; } if($row['theme'] == event) { echo"images/event_bg.gif"; }else{ echo"images/normal_bg.gif"; } } ?> Only problem is, if any of the 'if's are set in the database, eg. halloween or easter, it doesn't show a background, but if anything other than an if is set in the database, eg. '123456', then it will show my 'normal_bg'. Link to comment https://forums.phpfreaks.com/topic/130167-have-a-problem-in-my-code/ Share on other sites More sharing options...
trq Posted October 26, 2008 Share Posted October 26, 2008 All your comparisons need be.... if($row['theme'] == 'christmas') { Unless of course you have defined the constants christmas and friends somewhere. Link to comment https://forums.phpfreaks.com/topic/130167-have-a-problem-in-my-code/#findComment-675001 Share on other sites More sharing options...
adamjones Posted October 26, 2008 Author Share Posted October 26, 2008 Nope. Hasn't worked. Link to comment https://forums.phpfreaks.com/topic/130167-have-a-problem-in-my-code/#findComment-675002 Share on other sites More sharing options...
kenrbnsn Posted October 26, 2008 Share Posted October 26, 2008 Try this instead: <?php mysql_connect("localhost", "wowdream_dreams", "pass") or die(mysql_error()); mysql_select_db("wowdream_dreams") or die(mysql_error()); $result = mysql_query("SELECT * FROM theme") or die(mysql_error()); $valid_themes = array('christmas','easter','halloween','valentines','newyear','event'); while($row = mysql_fetch_assoc($result)) { if (in_array($rw['theme'],$valid_themes) echo 'images/' . $rw['theme'] . 'valentines_bg.gif'; else echo "images/normal_bg.gif"; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/130167-have-a-problem-in-my-code/#findComment-675006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.