You could use $_SESSION...
$sql = $db->query("SELECT * FROM table WHERE date BETWEEN '". $_SESSION['range']['from'] ."' AND '". $_SESSION['range']['to'] ."'");
... which will persist for the browser session.
Question
I am working on a PHP and MySQL based application in which I am processing mysql data tables for one week data at a time. All my PHP scripts will run in a particular sequence and process the data in all tables (upto 15 tables) for given week.
Presently I have written the date filter in WHERE clause and application is working fine.
IS there any way by which I can set the week's date range at one place and all the queries are fired in all the tables with given date range.
I want this bcoz my application processes are growing and its hard to manage 20+ pages and 50+ queries written in it. I am using command line PHP.
Please suggest the technique if any. Thanks
No correct solution
OTHER TIPS
You could use $_SESSION...
$sql = $db->query("SELECT * FROM table WHERE date BETWEEN '". $_SESSION['range']['from'] ."' AND '". $_SESSION['range']['to'] ."'");
... which will persist for the browser session.
SELECT stuff from your_table
WHERE your_date_field > DATE_ADD(CURDATE(), INTERVAL - 7 DAY);
Run that once a week to get last 7 days, then hack it around to get the exact results you want.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add