Query Report
| From: | Manuel | Date: | Mon, 11 Sep 2000 07:27:19 +0000 |
| Subject: | Query Report | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-2780@lists.php.net to get a copy of this message | ||
Hi John,
I have made some progress on that report.
Because the report is for the past 12 months (fixed), I am going to loop it 12 times. I am using "SELECT DATE_SUB(datefield, interval 1 month)" to back up one month.
Get current date
loop 12 times
inside loop
select month by month for 12 mth
if record not exist
insert to temp tableelse
update to temp tableMy writing to table part have problem. My temp table results. Jan Feb A 10 B 5 A 15 B 10 How can I make it to:- Jan Feb A 10 15 B 5 10 My code for the if statements // check to see if the record exist $ressql="SELECT * from temp WHERE t_salesman=$l_salesman"; $ressql1 = mysql_query($ressql); $mthvar = "mth" . $getmth3; //if not exists if (!$ressql1) $updsql = "INSERT INTO temp (t_lawyer,$mthvar) VALUES ('$l_salesman',$salescount)"; else $updsql = "UPDATE temp set $mthvar = $salescount where $t_salesman=$l_salesman"; $updsql1 = mysql_query($updsql); Any help would be appreciated.