I need some advise on implementing my database schema properly. I have a cron script whose main functions are to Parse HTML docs => Create a DB tbl => Insert Records
I am used to run this script only once per month but I need to do it more frequently which means my database tables will increase significantly. At the moment my tables follow this format : table_03 where the last two digits represent the current month.
Now I am considering using PHP time() function to replace the current month.
My first question, is this a good way to approach it ?
My second issue is how do you go about creating a dynamic SELECT statement that fetches the last two tables in a Database based on their date ? or could be better to know if there is an MySQL query that does this job instead of relying of the table names ?
e.g
table_29_03 // 29 March
table_26_03 // 26 Mar...
table_25_03
...
My query should return the difference between the last two or three table, but not having consistent dates ( as monthly ) I am not sure how to do it.
At the moment I am doing the following :
$thisMonth = 'table_'.date('m');
$PrevMonth = 'table_'.date('m', strtotime('first day of last month'));
// find new records in this table not available in previous one
$sql = "
SELECT * FROM `".$thisMonth."` WHERE `".$thisMonth."`.`id`
NOT IN (
SELECT `".$PrevMonth."`.`id`
FROM `".$PrevMonth."`
WHERE `".$thisMonth."`.`id` = `".$PrevMonth."`.`id`
); ";