jhodara Posted December 12, 2010 Share Posted December 12, 2010 Hi folks, I was wondering how to do this. I want the if statement to detect if the query string has any of these values. so im trying to assign them all to the same variable. However, this code wont work. Whats the trick here? <?php $primary=$_GET['intro']; $primary=$_GET['port']; $primary=$_GET['about']; $primary=$_GET['contact']; if(isset($primary)){ echo "<img src='graphics/left-a.png'>";} else {echo "<img src='graphics/leftb.png'>";}?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 12, 2010 Share Posted December 12, 2010 What actually is your question? Quote Link to comment Share on other sites More sharing options...
jhodara Posted December 12, 2010 Author Share Posted December 12, 2010 Just added my question Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 12, 2010 Share Posted December 12, 2010 I *think* this is what you really want to do if(isset($_GET['intro']) || isset($_GET['port']) || isset($_GET['about']) || isset($_GET['contact'])) { echo "<img src='graphics/left-a.png'>"; } else { echo "<img src='graphics/leftb.png'>"; } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 12, 2010 Share Posted December 12, 2010 For that, you'd need to use an array. Quote Link to comment Share on other sites More sharing options...
jhodara Posted December 12, 2010 Author Share Posted December 12, 2010 Ya that worked thanks. Although I thought I could use a variable to simplify the code. whatever Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 12, 2010 Share Posted December 12, 2010 <?php $primary=array(); if(isset($_GET['intro'])){ $primary['intro']=$_GET['intro']; $primarykeys[]='intro'; } if(isset($_GET['port'])){ $primary['port']=$_GET['port']; $primarykeys[]='port'; } if(isset($_GET['about'])){ $primary['about']=$_GET['about']; $primarykeys[]='about'; } if(isset($_GET['contact'])){ $primary['contact']=$_GET['contact']; $primarykeys[]='contact'; } if(count($primary)>0){ echo '<img src="graphics/left-a.png">'; }else{ echo '<img src="graphics/leftb.png">'; } ?> Would this be what you want? As here you can actually use the get data later on, and no need to check if they exist anymore. Quote Link to comment Share on other sites More sharing options...
jhodara Posted December 12, 2010 Author Share Posted December 12, 2010 Ya that would work. Thanks. 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.