Date Range with MySQL

Discussion in 'PHP' started by Jabowen, Dec 2, 2010.

  1. #1
    Good evening!

    I call on you to give me a helping hand :( I'v run into a problem using Dreamweaver, basically I am creating a 'log' database for something in work and what I would like to do is be able to have a search page (see attachment image #3) and obviously when you click groovie you get the results.

    I'm having trouble creating the results page, anyone point me in the right direction in terms of what I need to put in the recordset to pull the information from the URL parameter?

    Hopefully someone can give me a hand!

    Thanks for your time,
    Jac
     

    Attached Files:

    • 3.PNG
      3.PNG
      File size:
      9 KB
      Views:
      132
    Jabowen, Dec 2, 2010 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Hi ,
    You did not mentioned if you use POST or GET or your field names but I will be showing you a general solution that you can addapt to your needs.

    lets assume your From date fields have the following names : f_day,f_month,f_year ( and that they all are numeric (f_month select value is date("n",...)) , same for To fields : t_dat,t_month,t_year.

    The code would be :
    
    $from = mktime(0,0,0,$_POST['f_month'],$_POST['f_day'],$_POST['f_year']);
    $to = mktime(0,0,0,$_POST['t_month'],$_POST['t_day'],$_POST['t_year']);
    
    $results_search = mysql_query("SELECT * FROM table WHERE date_field BETWEEN '".date("Y-m-d",$from)."' AND '".date("Y-m-d",$to)."'");
    if(mysql_num_rows($result_search) > 0)
    {
    //print results
    } else {
    echo 'No results found !';
    }
    
    PHP:
    Hope that clears things up.
     
    tvoodoo, Dec 3, 2010 IP
    Jabowen likes this.
  3. nadeem3366

    nadeem3366 Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Yup. thats a correct, now i think the problems is solved for him, now its up to him that how he wants to print the result.
     
    nadeem3366, Dec 3, 2010 IP
  4. Jabowen

    Jabowen Active Member

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hey guys, thanks for your replys. I will give it a go now! In answer to your question yes it was a get field, shouldve known to post the code and what have you ha!

    Thanks again!
    Jac
     
    Jabowen, Dec 3, 2010 IP