Jump to content

bcoffin

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by bcoffin

  1. Hi Fenway, That's where I get confused. I wanted to just put it all in one query string, but I don't know how to distinguish between ANDs and ORs for something like that? Here's an example I'm currently using: if(isset($_POST['director'])) $director = "DIRECTOR = '$_POST['director']" if(isset($_POST['terms'])) { $term_in = explode(" ",$_POST['terms']); foreach($term_in as $k=>$v) { $terms .= "OR $terms LIKE '%$v%'"; } $terms = ltrim($terms,"OR"); } else { $terms = ""; } foreach($_POST['genre'] as $genre_key=>$genre_category) { if(isset($genre_category)) $genre = "OR $genre_category='1'"; } $genre = ltrim($genre,"OR"); "SELECT * FROM listings WHERE $director $terms $genre ORDER BY title ASC"; But obviously the ANDs and ORs get screwy... More help, please? Benny [!--quoteo(post=333723:date=Jan 5 2006, 06:14 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 5 2006, 06:14 PM) 333723[/snapback][/div][div class=\'quotemain\'][!--quotec--] Well, you need to first determine which conditions have been inputted (in PHP), and make a (possibly) combined query that, in principle, can include all three. Usually, this requires JOINing an extra table for each addition condition, and updating the WHERE clause accrodingly. I built the query string in middleware, and then run the query. Why don't you post what you have for each _individual_ query, and then try and combine them.
  2. I'm putting together a movie listing site, where users can search the database via a number of different search options. They are: [ DROPDOWN: Director Name ] [ FREE TEXT: search terms ] [ ] Check box: Genre 1 [ ] Check box: Genre 2... I'd like for MySQL searching as follows, but I really need your advice on how to do this: If a director name is selected from the drop down ALL results must be by that director. If free text search terms are specified ALL results must have at least one of the search terms. If checkboxes are selected ALL results must be in at least one of those selected genre categories. Right now, the genre is a 1/0 tinyint in the movie record. Can somebody please give me some advice about how to set up a mysql query to do this?? Thanks, Benny
×
×
  • 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.