Jump to content

Adding a string into the url


jonw118

Recommended Posts

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'];
?>

Link to comment
https://forums.phpfreaks.com/topic/137477-adding-a-string-into-the-url/
Share on other sites

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'];
}
?>

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'];

?>

<?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'];
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.