danjapro Posted October 17, 2011 Share Posted October 17, 2011 I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/249272-issue-with-my-simple-if-statment/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 17, 2011 Share Posted October 17, 2011 try this <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID = 1) { $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } else { if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } else { if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } } } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> EDIT: UPDATED Quote Link to comment https://forums.phpfreaks.com/topic/249272-issue-with-my-simple-if-statment/#findComment-1280003 Share on other sites More sharing options...
Psycho Posted October 17, 2011 Share Posted October 17, 2011 Well, all of your IF statements are out of wack. if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } // . . . The first if statement will be true as long as $bgimgID exists and cannot be interpreted as a boolean false (e.g. FALSE, 0, etc.). All the conditions that follow are ASSIGNMENTS not COMPARISONS. The second if() above is testing if you can assign the number 2 to the variable $bgimgID. That would return true every time. You should probably be suing something like if($bgimgID == 1){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID == 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } Note the double equal signs for comparisons Quote Link to comment https://forums.phpfreaks.com/topic/249272-issue-with-my-simple-if-statment/#findComment-1280004 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 17, 2011 Share Posted October 17, 2011 opps. sorry, i just added the else and if to the code, didnt really read through the code. Quote Link to comment https://forums.phpfreaks.com/topic/249272-issue-with-my-simple-if-statment/#findComment-1280006 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.