Jump to content

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



Link to comment
https://forums.phpfreaks.com/topic/10606-mysql-wildcards-in-url/
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--]
Link to comment
https://forums.phpfreaks.com/topic/10606-mysql-wildcards-in-url/#findComment-41389
Share on other sites

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.