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'. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
adamjones Posted October 26, 2008 Author Share Posted October 26, 2008 Nope. Hasn't worked. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.