0

Hi all - also new to PHP/SQL and have a different question on a similar question posted -
I need to create a page in php that allows the user to select a date range to and from.
Howver, the date stored in the database is unix such as 1494548767
Was thinking a drop down calender might work too - just not sure where to go with this or how to search by date in this situation.
If you need table structure or anything else - please reply and I'll provide what is needed to help find a solution.
Thanks in advance!
J

4
Contributors
6
Replies
28
Views
6 Months
Discussion Span
Last Post by Amelia_4
0

Yep, Been there done that thus how/why I landed here.
The key to my question was to see and use regular dates on the search page although the search range is a unix based date code NOT MM-DD-YYY. Maybe I didn't explain that clearly, my apologies.

0

You need to convert the dates users enter to Unix timestamps. You can do that either in PHP or MySQL (see UNIX_TIMESTAMP()).

0

The exact syntax depends on how you're interacting with your database (MySQLi, PDO, etc.). You basically need to take the POSTed form values, do some straightforward validation to make sure that the user hasn't entered anything dangerous, then insert the values into the query:

$from = mysqli_real_escape_string($_POST['fromdate']);
$to = mysqli_real_escape_string($_POST['todate']);
$sql = "select id, name, brand, datecreated from product where datecreated between '$from' and 
'$to' order by datecreated desc";

The action on the form would be whichever page you place the above code in - it could be the same page as the form. In that case, the action would be

<?php echo basename($_SERVER['PHP_SELF']); ?>

and the method would be POST.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.