#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    35
    Rep Power
    14
    Hi,

    I've looked through several mysql tutorials and can't figure out how to do a search and match.

    I have a form that has a field to enter "City" and checkboxes for "Age". For example:
    18 - 20
    21 - 25
    26 - 30
    31 - 35
    36 - 40
    41 - 45
    46 - 50
    51 - 55
    56 - 60

    They then select to see listings between January and March, April and June, July and September, or October and December.

    How in the world do I write the search statement for this? I'm using a php page.

    If anyone could give me a short example or point me in the right direction I would be very thankful.

    Tim
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    Hmm...depends on how your values are set up for the select statements. Here's one way I can think of. For the age, have it set up like this:

    <select name=age>
    <option value="18 - 20">18 - 20</option>
    <option value="21 - 25">21 - 25</option>
    etc...

    For the months, like this:

    <select name=month>
    <option value=1>January - March</option>
    <option value=4>April - June</option>
    <option value=7>July - September</option>
    <option value=10>October - December</option>

    Then, assuming you have an age column, and some sort of timestamp or date column (no varchar!) in your database, use something like this:

    $l_age = substr($age,0,2);
    $u_age = substr($age,-2);
    $query = "SELECT * FROM your_table WHERE (age BETWEEN $l_age AND $u_age) AND (MONTH(timestamp_column) BETWEEN $month AND ($month + 3))";
    $result = mysql_query($query);

    Hope that works for you.

    ---John Holmes...


    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************

Similar Threads

  1. Need advice designing a usage tracking database (MySQL)
    By Randolpho in forum Database Management
    Replies: 0
    Last Post: February 13th, 2004, 04:11 PM

IMN logo majestic logo threadwatch logo seochat tools logo