I have read the posting guidelines, seen the video (great! 🙂 ), and have searched every key word I can think of for this, and still have not been able to find an answer. When I googled, I got some more info, but not a concrete answer on what will work and what won't, just that lots of script may be needed. Please forgive me if there is another thread elsewhere - I couldn't find it.
Here is the basis for my question: a pgsql database with columns for name, category, city, state and zip. I want a search form that will allow users to choose category from list; city, state and zip are all user definable. Category and state are required, but city and zip are optional. I want a query that will search the db and pull out names that match all submitted criteria. I am at work right now so I have not been able to test this, but I wanted to get any help I could. Here is what I have right now.
<?php
$dbconn=pg_connect("host=localhost port=5432 dbname=business");
if (!dbconn){
echo "An error occurred. \n";
exit;
}
$city1=(boolean)$city // $city is variable from form - forces boolean
$zip1=(boolean)$zip // $zip is variable from form - forces boolean
IF $city1=(!FALSE) AND $zip1=(!FALSE){
$results[]=(SELECT table.name WHERE table.category=$category AND
table.city=$city AND
table.state=$state AND
table.zip=$zip;
}
ELSEIF $city1=(!FALSE) AND $zip1=(FALSE){
$results[]=(SELECT table.name WHERE table.category=$category AND
table.city=$city AND
table.state=$state;
}
ELSEIF $city1=(FALSE) AND $zip1=(!FALSE){
$results[]=(SELECT table.name WHERE table.category=$category AND
table.state=$state AND
table.zip=$zip;
}
ELSE {
$results[]=(SELECT table.name WHERE table.category=$category AND
table.state=$state;
}
This is not the entire script - the other reason I can't test just yet is it's not completed. Suffice it to say $category, $city, $state, $zip all come from the form; $city1 and $zip1 are forced boolean copies of $city and $zip to make true/false decisions in the IF statement; $results is supposed to be an array with the output from the query for listing on a results page.
Is this completely wrong, or will it work?
fdgloworm