<?php
require_once('header.php');
include_once("classes/pageclass.php");
require_once('check_user.php');

$sql = "select m.*,cm.category_id,cm.hits_num,cm.down_num,cm.fav_num,pic.thumbnail_path,fav.id,fav.favtime from {$tablepre}favorites fav 
        inner join {$tablepre}message m on fav.msg_id=m.msg_id
		inner join {$tablepre}categorymng cm on cm.msg_id=m.msg_id
	    inner join {$tablepre}attachmng pic ON pic.msg_id = m.msg_id
	    where pic.index_box=1 and fav.scuser_id='".$_SESSION["uid"]."' and m.msg_status=1 GROUP BY cm.msg_id order by m.msg_id desc,pic.attach_id asc"; 

$rs      = $db->query($sql);
$myrow   = $rs->fetchAll();
$numrows = count($myrow);

$p       = new ft_page;
$p->setvar($plink); 
$p->set($site_num,$numrows,$psize); 
$rsx=$db->query($sql." limit ".$p->limit(),true);

if ($numrows!=0){
	 $i=0;
	 $ListArray = array();
	 while ($myrow = $rsx->fetch()) {
	     $ListArray[$i]['id']=$myrow['id'];
		 $ListArray[$i]['msg_id']=$myrow['msg_id'];
		 $ListArray[$i]['msg_title']=$myrow['msg_title'];
		 $ListArray[$i]['category_id']=$myrow['category_id'];
		 $ListArray[$i]['msg_demourl']=$myrow['msg_demourl'];		 
		 $ListArray[$i]['msg_downurl']=$myrow['msg_downurl'];
		 $ListArray[$i]['msg_integral']=$myrow['msg_integral'];
		 $ListArray[$i]['msg_poster']=$myrow['msg_poster'];
		 $ListArray[$i]['msg_url']=$myrow['msg_url'];
		 $ListArray[$i]['thumbnail_path']=$myrow['thumbnail_path'];
		 $ListArray[$i]['hits_num']=$myrow['hits_num'];
		 $ListArray[$i]['down_num']=$myrow['down_num'];
		 $ListArray[$i]['msg_starttime']=$myrow['msg_starttime'];
		 $ListArray[$i]['msg_endtime']=$myrow['msg_endtime'];
		 $ListArray[$i]['fav_num']=$myrow['fav_num'];
		 $ListArray[$i]['favtime']=$myrow['favtime'];
		 $ListArray[$i]['msg_createtime']=dateFormat($myrow['msg_createtime'],'Y-m-d');
		 $i++;
	 }
}

$pager=$p->output(1);
include($template->getfile('usercenter'));
?>