isaac_cm Posted May 27, 2006 Share Posted May 27, 2006 hello,I have a numeric paramter that I give it's value in the url like thatproduct.php?category_id=1sometimes 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 productsWHERE (category_id = colname)-------------------------------------------I use $_GET['category_id'] for colname parameterthanks Link to comment https://forums.phpfreaks.com/topic/10606-mysql-wildcards-in-url/ Share on other sites More sharing options...
jeremywesselman Posted June 3, 2006 Share Posted June 3, 2006 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]<?phpif(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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.