This topic is locked

New table generated every month / quarter

12/1/2011 11:47:39 AM
PHPRunner General questions
C
CK. author

Dear All,
My application will automatic generate new table in every month & every quarter. eg. sales2011m(01..12) [Jan to Dec], sales2011q(1..4) [4 Quarters]. (for this case is Dec & Q4) All monthly transactions will stored in sales2011m12 and during end of month, the total sales will update to sales2011q4.
Now I'll like to create a monthly report which allow me to select year, month to view and the other Quarterly report allow me to select year, quarter to view.
My question is, how to make phprunner to select and read the correct table in order to generate the report base on month / quarter selected?
eg. select * from dynamic_table_name...
Regards,

php.Newbie

C
cgphp 12/2/2011
$year = date("Y");

$month = date("n");
$qtr = array();

$qtr[0]=array(1,2,3);

$qtr[1]=array(4,5,6);

$qtr[2]=array(7,8,9);

$qtr[3]=array(10,11,12);
foreach($qtr as $key => $value)

{

if(in_array($month,$value))

{

$quarter = $key + 1;

break;

}

}
$month_table = "sales".$year."m".$month;

$quarter_table = "sales".$year."q".$quarter;
$month_sql = "SELECT * FROM ".$month_table." WHERE ....";

$quarter_sql = "SELECT * FROM ".$quarter_table." WHERE ....";
C
CK. author 12/2/2011


$year = date("Y");

$month = date("n");
$qtr = array();

$qtr[0]=array(1,2,3);

$qtr[1]=array(4,5,6);

$qtr[2]=array(7,8,9);

$qtr[3]=array(10,11,12);
foreach($qtr as $key => $value)

{

if(in_array($month,$value))

{

$quarter = $key + 1;

break;

}

}
$month_table = "sales".$year."m".$month;

$quarter_table = "sales".$year."q".$quarter;
$month_sql = "SELECT * FROM ".$month_table." WHERE ....";

$quarter_sql = "SELECT * FROM ".$quarter_table." WHERE ....";



This is good for current year and month only. What I think is setup pulldown options for user to select the year and month. Just like create a search form without load a table on startup. Assign the table name like above code after user selection.
Thanks in advance.
Regards,

php.Newbie

C
cgphp 12/2/2011

You have only to assign to the $year and $month variables the option values from the dropdowns.