prouty Posted December 19, 2006 Share Posted December 19, 2006 Thanks for all the great responses. I found an elegant solution (and am embarassed that this VERY SIMPLE approach eluded me).In the creation of the drop down list, I simply had to change the first option so that it reported a value of ' ' when "Please select a fruit..." is submitted:echo "<option value=''>Please select a fruit...</option>";Works from there without a hitch.Thanks again to everyone who provided advice.ProutyI am posting with a request for information.Here's a simplified example what I've got: 1. mysql database of all fruit stands in florida organized by type of fruit sold (apples, oranges, grapes, mangos)2. a php page that displays a listing of all fruit stands.3. a drop down list that allows the user to display only stands the sell a specific fruit when selected and a button (go) is pressed.So, a web page user could view this page, see all fruit stands, then select, say, grapes, from the drop down, click "go" and the page refreshes to display onle the grape stands. So far so good.When the initial (unfiltered) page loads, the text in the drop down (initial value) is "Please select a fruit...".I am trying to find a way so that when someone clicks "go" and "Please select a fruit..." is the selection (as opposed to a fruit fromt the list), the entire (unfiltered) list is presented. Right now it produces an empty list.I guess my question is this: When a fruit is selected it queries the mysql database with the "WHERE" value 'qfruit' for only fruitstands of that particular fruit...SELECT * FROM fruitstands WHERE fruit='qfruit'; What value should 'qfruit' be to return ALL fruits and display all fruitstands?This way, when a user clicks go and "Please select a fruit..." is the selected option, all fruitstands are displayed.Any help or guidance is appreciated.Thanks.prouty Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/ Share on other sites More sharing options...
makeshift_theory Posted December 19, 2006 Share Posted December 19, 2006 Try this:[code]SELECT * FROM fruitstands; [/code]You can also order them if you wish like so:[code]SELECT * FROM fruitstands ORDER BY id;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/#findComment-144452 Share on other sites More sharing options...
prouty Posted December 19, 2006 Author Share Posted December 19, 2006 Thanks...that will clearly produce all fruitstands...When the initial variable is sent to the page (when qfruits='Please select a fruit...') it gets popped into the WHERE part of the SELECT string.So I'm looking for a way when qfruits='Please select a fruit...' to yield the same results as SELECT * from fruitstands; Thanks again for the reply... Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/#findComment-144467 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 If you use:SELECT * FROM fruitstands WHERE fruit LIKE = '%qfruit%'; You are then searching for an entry that contains the search string, this way if the search string is empty, it should return all entries. The only downside of is if you have an entry that part of which matches another entry, ieif you have one entry 'aaa' and another entry 'aaabbb', 'aaabbb' will be returned when you filter by 'aaa' Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/#findComment-144468 Share on other sites More sharing options...
chiprivers Posted December 19, 2006 Share Posted December 19, 2006 You may also want to declare a default value:<?phpif (!isset($_POST['qfruit'])) {$qfruit = "";}?> Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/#findComment-144469 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Just put the whole WHERE clause into an if statement...[code]<?php$sql = "SELECT * FROM fruitstands";if (isset($_POST['qfruit']) && ($_POST['qfruit'] != "Please select a fruit..."){ $sql .= " WHERE fruit = '".$_POST['qfruit']."'";}[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31232-solved-rfi-php-query-against-mysql-to-return-all-resultsfrom-a-drop-down/#findComment-144489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.