Hi All, I’m new to PHP/MySQL and am stumped with what should be a simple process of posting a date range to a PHP script that will query data for the selected range. The script receives the two dates as confirmed when I echo for the variables. For example:
<?php echo $_POST [“date3”]; ?> to
<?php echo $_POST [“date4”];?>
This properly displays “2011-01-08 to 2011-01-09” when I set those dates in the calendar form and submit. But what I can’t figure out is how to create variables for these dates and query the database for the submitted range. If I hard code a date into the query using “WHERE posttime LIKE '%2011-01-08%” the query succeeds and produces expected results:
$result = mysql_query(‘SELECT points, service, posttime, network, name, value FROM points, redirects WHERE points.qotdid = redirects.qotdid AND points.posttime LIKE “%2011-01-08%” ORDER BY redirects.network, redirects.name, points.posttime’);
How should the query look if I want to replace the static date with the range passed from the form? I would assume:
$result = mysql_query(‘SELECT points, service, posttime, network, name, value FROM points, redirects WHERE points.qotdid = redirects.qotdid AND points.posttime BETWEEN $fromdate and $todate ORDER BY redirects.network, redirects.name, points.posttime’);
Sorry I failed to include the quotes, although I tried that too…it gives me this error:
Parse error: syntax error, unexpected T_VARIABLE in /Applications/MAMP/htdocs/offers/admin/querystats.php on line 45
Any idea why? It’s almost as if the ‘BETWEEN’ operator is not recognized - it doesn’t change colors in my text editor like ‘SELECT’, ‘FROM’, ‘WHERE’ etc.
Do I have to do anything to convert the posted date format to how the time stamps are recorded in the database? For example, the form is using ‘YYYY-MM-DD’ and the database includes time as in ‘YYYY-MM-DD HH:MM:SS’.