<?
if(!(isset($_SESSION))){session_start();}
$mAccount=$_SESSION['mAccount'];
$mId=$_SESSION['mId'];
include("../db.php");

require_once("../function.php");

$type=$_GET['type'];

$popstr="SELECT RAISE.MID, COUNT( RAISE.MID ) ,ACTIVITY.TID,ACTIVITY.AID, RAISE.RID
FROM ACTIVITY
INNER JOIN RAISE ON RAISE.AID = ACTIVITY.AID

INNER JOIN  TAKES
 ON TAKES.RID = RAISE.RID
WHERE ACTIVITY.TID='".$type."'
GROUP BY RAISE.MID, ACTIVITY.AID,ACTIVITY.TID,RAISE.RID
ORDER BY  COUNT( RAISE.MID ) DESC ";

$str = oci_parse($conn,$popstr) or die('Insert error');
oci_execute($str);
$num=oci_fetch_all($str,$results);
if($num!=''){
oci_execute($str);
echo "<table>";
	for($i=0;$i<5;$i++){
		if(list($rmId,$amount)=oci_fetch_row($str)){
		
	
			$str_1 = oci_parse($conn,"select MID,MACCOUNT from MEMBER where MID='$rmId'") or die('Insert error');
oci_execute($str_1);
			while(list($mId,$macc)=oci_fetch_row($str_1)){
				echo "<tr><th colspan='2'><center>第".($i+1)."名</center></th>";
			
							echo "<td width='100'><a href='../member/show_member_detail.php?mId=$mId'>$macc</a><br>";
				
				
				echo"<br>目前總揪到：$amount".人."</td></tr>";
			
			}//end of while
		}//end of if
	}//end of for

}//end of if
else{echo"<tr><td>本月還沒有購物揪團人氣王哦!!<br>請大家踴躍發起揪團!!<td></tr>";}  

?>