//select frequency Jan-1
$jan1=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-01' and '01-07'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND activity.UNI_ID=$university");
$num1=mysql_num_rows($jan1);
//select frequency Jan-2
$jan2=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-08' and '01-14'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND activity.UNI_ID=$university");
$num2=mysql_num_rows($jan2);
//select frequency Jan-3
$jan3=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-15' and '01-21'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num3=mysql_num_rows($jan3);
//select frequency Jan-4
$jan4=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-22' and '01-28'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num4=mysql_num_rows($jan4);
//select frequency Jan-5
$jan5=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-29' and '01-31'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num5=mysql_num_rows($jan5);
ตัวแปรที่เปลี่ยน
1.$jan1 ขอเปลี่ยนเป็น $week1,$week2,$week3,...,$week60
2.$num1,$num2,$num3,...,$num60
3.ตรง BETWEEN เฉพาะ '01-01' and '01-07','01-08' and '01-14','01-15' and '01-21','01-22' and '01-28', '01-29' and '01-31' มี 5 สัปดาห์ต่อเดือน
Code (PHP)
while($objResult1 = mysql_fetch_array($objQuery1)) {
$university=$objResult1['id'];
$seYear=2012;
//select frequency Jan-1
$jan1=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-01' and '01-07'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND activity.UNI_ID=$university");
$num1=mysql_num_rows($jan1);
//select frequency Jan-2
$jan2=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-08' and '01-14'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND activity.UNI_ID=$university");
$num2=mysql_num_rows($jan2);
//select frequency Jan-3
$jan3=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-15' and '01-21'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num3=mysql_num_rows($jan3);
//select frequency Jan-4
$jan4=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-22' and '01-28'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num4=mysql_num_rows($jan4);
//select frequency Jan-5
$jan5=mysql_query("SELECT * FROM register,activity WHERE register.ACT_ID=activity.ACT_ID
AND SUBSTRING(activity.ACT_DATE FROM 6 FOR 10) BETWEEN '01-29' and '01-31'
AND SUBSTRING(activity.ACT_DATE FROM 1 FOR 4) = $seYear
AND rdtc_activity.UNI_ID=$university");
$num5=mysql_num_rows($jan5);
}