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'>";}?> Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/ Share on other sites More sharing options...
Pikachu2000 Posted December 12, 2010 Share Posted December 12, 2010 What actually is your question? Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145970 Share on other sites More sharing options...
jhodara Posted December 12, 2010 Author Share Posted December 12, 2010 Just added my question Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145974 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'>"; } Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145976 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. Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145978 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 Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145980 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. Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1145981 Share on other sites More sharing options...
jhodara Posted December 12, 2010 Author Share Posted December 12, 2010 Ya that would work. Thanks. Link to comment https://forums.phpfreaks.com/topic/221359-assigning-multiple-values-to-one-variable/#findComment-1146019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.