Jump to content


Photo

mysql wildcards in url


  • Please log in to reply
1 reply to this topic

#1 isaac_cm

isaac_cm
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 27 May 2006 - 10:44 PM

hello,
I have a numeric paramter that I give it's value in the url like that

product.php?category_id=1

sometimes I need to display all the categories how to do that without making a second page , is there a way that I can pass a wildcard character to the select syntax so I get all records ?

------------------------------------
sql :

SELECT *
FROM products
WHERE (category_id = colname)

-------------------------------------------
I use $_GET['category_id'] for colname parameter


thanks





#2 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 03 June 2006 - 06:10 AM

You can do that by not setting the category_id variable or by setting it to 'all'. Then you will need to do a check on it to determine which sql statement you will need to run.

product.php?category_id=all

Then you would check it like this.

<?php
if(isset($_GET['category_id']))
{
    $category_id = $_GET['category_id'];

    if($category_id == 'all')
    {
        $sql = "SELECT * FROM products";
    }
    else
    {
        $sql = "SELECT * FROM products WHERE category_id = $category_id";
    }
}
?>

And then you can run your query with $sql.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users