Register

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
    Posts
    241
    Member #
    15910
    Hi
    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?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    1: It sounds like what you need to do is check if they selected the "Any" option for Category. If so, change your query to something like
    PHP Code:
    $query mysql_query("SELECT (columns) FROM (table) WHERE startdate = 'dd/mm/yyyy'"); 
    That does not put any restrictions on what the values of category or state are so all will be returned.

    2: What is the column type of start date? If it is VARCHAR then you its simply
    PHP Code:
    $query mysql_query("SELECT (columns) FROM (table) WHERE startdate = \"$year-$month-$day\""); 
    Untested.

    3: Wow, thats a toughie. There is probably a database expert out there but I would like to think the whole query is analysed first and then the mysql engine knows that all conditions are equally important (because you use the AND keyword). So when it encounters the first conditional statement (AND startdate = '.....') a "temporary" table is created (not in the physical sense) and then the query runs the second conditional statement and this goes on until all conditional statements have been executed and you are left with a table ($result normally in PHP )which matches all your conditional statements.


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:09 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com