Still needing help with dynamic queries

From: Date: Thu, 30 Nov 2000 22:31:52 +0000
Subject: Still needing help with dynamic queries
Groups: php.general 
Request: Send a blank email to php-general+get-28129@lists.php.net to get a copy of this message
OK, I've read over the recent responses to creating dynamic mysql queries and I've tried making my own and modeling mine after others....but I'm getting knowhere very quickly, besides retyping lots of conditional statements. Here is what I need: I have a form to search a database which stores about 15 pieces of info about each person. On the form ( http://www.politics2004.com/personals/search.html ) you have 6 options to search by, leaving all blank will return all results in the DB. At the bottom I have a check box that will make it search for all the criteria, while not checking it will return those with partial matches, as well. Anyone willing to bang out a block of code like this would have my gratitude. I'm just about to give up on this and make the search simpler, if I can't figure it out. Thank you much! Jon here is the last of about 15 different tries at this, though it's only partially done and of course not working: "blank" is the value given from a blank SELECT style form field. snippet of code >>>> print "Your choices to search by are: $search_sex, $search_city, $search_state, $search_orientation, $search_status, $search_race, $search_option<BR><BR>"; if ( ! $search_option == "AND" ) // Not sure how to integrate these { $search_option = "OR"; } $db_query = "SELECT * FROM personals WHERE "; if ( ! $search_sex == "blank" ) { $db_query .= "_sex='$search_sex' "; } if ( ! $search_city == "" ) { $db_query .= "_city='$search_city' "; } if ( ! $search_state == "blank" ) { $db_query .= "_state='$search_state' "; } if ( ! $search_orientation == "blank" ) { $db_query .= "_orientation='$search_orientation' "; } if ( ! $search_status == "blank" ) { $db_query .= "_status='$search_status' "; } if ( ! $search_race == "blank" ) { $db_query .= "_race='$search_race' "; } $db_query .= "ORDER BY _date"; if ( $search_sex == "blank" && $search_city == "" && $search_state == "blan k" && $search_orientation == "blank" && $search_status == "blank" && $search_race == "blank" ) { $db_query = "SELECT * FROM personals ORDER BY _date"; } print "Query is: $db_query, that's all<BR><BR>"; <<<<<<

« previous php.general (#28129) next »