Jump to content

Archived

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

isaac_cm

mysql wildcards in url

Recommended Posts

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



Share this post


Link to post
Share on other sites
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.

[code]product.php?category_id=all[/code]

Then you would check it like this.

[code]<?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";
    }
}
?>[/code]

And then you can run your query with $sql.

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

Share this post


Link to post
Share on other sites

×

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.