If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Member #
    I have a drop down form with a few selections.
    The Mysql query I am writing to bring up results is currently as follows:
    $query=mysql_query("SELECT * FROM events WHERE category='$kat' AND startdate= '..............' AND state='$state' ORDER BY id DESC LIMIT 4");
    My questions are:
    1-When the user selects a category and state in the drop down menu, I can bring up those results. But if the user selects "Any" for the category (and for state), how do I bring up the results belonging to any category and/or any state?
    2-Startdate column in the database contains the dates as yyyy-mm-dd...In the query above, how can I make it equal (how is the syntax) to a certain date based on $day $month $year variables set up earlier during the execution of php code?
    3-General question about the type of queries above: Just trying to understand the efficiency...How does it search for all the criteria? With all those "AND" statemens above, does it look at the first criteria and then eliminates everything else and then look for the second criteria in the reamining results and then the third and so on?


  3. #2
    Senior Member
    Join Date
    Dec 2008
    Member #
    1 times
    dont have much time but lemme take a stab

    #1, check if they selected any for either
    PHP Code:
    $cat=="any" && $state=="any"){
    $sqlStatement="SELECT * FROM Events WHERE startdate=".$date
    }else if($cat=="any" && $state!="any"){
    $sqlStatement="SELECT * FROM Events WHERE startdate=".$date." AND state=".$state;
    }else if(
    $cat!="any" && $state=="any"){
    $sqlStatement="SELECT * FROM Events WHERE startdate=".$date." AND category=".$cat;
    }else if(
    $cat!="any" && $state!="any"){
    $sqlStatement="SELECT * FROM Events WHERE startdate=".$date." AND category=".$cat." AND state=".$state;
    #2 have you tried comparing the string?
    $phpDate=$year."-".$month."-".$day; //make sure this is the right format
    echo $phpDate; //check it

    #3 Not to sure about this either.
    Im assuming it does this

    where state="kentucky" and startdate="2004/04/05" and category="general"

    If a row doesnt meet state=kentucky, it skips to the next row, if it does, it will compare the startdate, if it doesnt meet the startdate=2004/04/05, it will skip to the next row etc etc

    Hope i helped

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 10:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: