Re: Need help with PHP & MySQL
by "rudy" <r937(at)interlog.com>
|
Date: |
Fri, 3 May 2002 20:00:33 -0400 |
To: |
"Lisa Bradshaw" <zibbler(at)web-design-cs.com>, <hwg-techniques(at)hwg.org> |
|
todo: View
Thread,
Original
|
|
hi lisa
you need to make the sql dynamic, by adding parts of the WHERE clause only
when something has been specified
each of the dropdown selects should have a "default state" -- often you
will see the html use something like "please select"
<select name="county">
<option value="0" selected="selected">Please select county</option>
<option value="1">Eins</option>
<option value="2">Zwo</option>
</select>
if the county value comes in as 0, your sql does not mention the county
column
that's because you want ALL county values
rule: you have to not mention any column in the WHERE clause that you want
all values of
if something other than the default is selected, then you must generate
that part of the WHERE clause
in cold fusion, it would look like this --
<CFQUERY NAME="queryname" DATASOURCE="#ds#">
select *
from Restaurants
WHERE 1=1
<CFIF form.county IS "0">
<CFELSE>
and County = '#form.county#'
</CFIF>
<CFIF form.alphaIS "0">
<CFELSE>
and Alpha = '#form.alpha#'
</CFIF>
<CFIF form.cuisine IS "0">
<CFELSE>
and Cuisine = '#form.cuisine#'
</CFIF>
<CFIF form.priceIS "0">
<CFELSE>
and Price = '#form.price#'
</CFIF>
</CFQUERY>
if you don't see why i started the WHERE clause with 1=1, please holler
rudy
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA