Jump to content

SOLVED: RFI: php query against mysql to return all results...from a drop down...


Recommended Posts

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.

Prouty





I 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
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...
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, ie

if you have one entry 'aaa' and another entry 'aaabbb', 'aaabbb' will be returned when you filter by 'aaa'
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]

Regards
Huggie
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.