Jump to content

Have a problem in my code


adamjones

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.