1 message in com.mysql.lists.mysqlA REPORTING QUERY
FromSent OnAttachments
Manuel11 Sep 2000 05:35 
Subject:A REPORTING QUERY
From:Manuel (man@buyee.com.sg)
Date:09/11/2000 05:35:53 AM
List:com.mysql.lists.mysql

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 table else update to temp table

My 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); $ressql2 = mysql_num_rows($ressql1); $mthvar = "mth" . $getmth3;

//if not exists if ($ressql2 <= 0) $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.