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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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