Jump to content

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

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.