jonw118 Posted December 18, 2008 Share Posted December 18, 2008 Hey there- Quick (I'm sure very easy question)... I have a script where it pulls where in the URL if you say xxxxxxx.com/page.php?cat=3 and it pulls records only with a category id of "3". I want to add one more variable to the string. Basically I want the url to pull only items from category 3 that have a location of "1". So, essentially I want: http://xxxxxx.com/page.php?cat=3&location=1 Everything I'm trying to make this happen with this code below is not working. Any advice would be very appreciated: <? if(!empty($cat)) $sql="select * from `inputinfo` where category='$cat' order by rank asc"; else $sql="select * from `inputinfo` order by rank asc"; $rez=mysql_query($sql,$dblnk); while($row=mysql_fetch_array($rez)){ $id=$row['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/ Share on other sites More sharing options...
mmarif4u Posted December 18, 2008 Share Posted December 18, 2008 Is this your complete code? If yes then it should be like this, one thing i did not see your location in query. <? if(!empty($cat)) { $sql="select * from `inputinfo` where category='$cat' order by rank asc"; } else { $sql="select * from `inputinfo` order by rank asc"; } $rez=mysql_query($sql,$dblnk); while($row=mysql_fetch_array($rez)){ $id=$row['id']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718455 Share on other sites More sharing options...
jonw118 Posted December 18, 2008 Author Share Posted December 18, 2008 That was the original code... I altered it to this, but didn't work: <? if(!empty($cat)) $sql="select * from `inputinfo` where category='$cat' order by rank asc"; $sql="select * from `inputinfo` where location='$loc' order by rank asc"; else $sql="select * from `inputinfo` order by rank asc"; $rez=mysql_query($sql,$dblnk); while($row=mysql_fetch_array($rez)){ $id=$row['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718457 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 <?php if ($_GET['cat'] && $_GET['location']) { $cat = (int) $_GET['cat']; $loc = (int) $_GET['location']; $sql="select * from `inputinfo` where category='$cat' and location = '$loc' order by rank asc"; } else { $sql="select * from `inputinfo` order by rank asc"; } $rez=mysql_query($sql,$dblnk); while($row=mysql_fetch_array($rez)){ $id=$row['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718460 Share on other sites More sharing options...
jonw118 Posted December 18, 2008 Author Share Posted December 18, 2008 Crayon... thank you, it makes sense. But unfortunately, it isn't working. Here's the URL I'm using: xxxxx.com/page.php?cat=1&loc=1 No matter what number I put in the "&loc=" it doesn't make a difference. Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718465 Share on other sites More sharing options...
mmarif4u Posted December 18, 2008 Share Posted December 18, 2008 Of course it will not work, change this: $loc = (int) $_GET['location']; to this: $loc = (int) $_GET['loc']; And this: if ($_GET['cat'] && $_GET['location']) to this: if ($_GET['cat'] && $_GET['loc']) And also } at the end for while loop. Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718467 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 And also } at the end for while loop. I just assumed he was closing out his php tag to put some html inside the loop or something. You know what they say about assuming... Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718473 Share on other sites More sharing options...
mmarif4u Posted December 18, 2008 Share Posted December 18, 2008 May be your right, but some time noob did these simple mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/#findComment-718477 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.