[981]PHP入門+XOOPS模組設計
<?php
function tad_contact_search($queryarray, $andor, $limit, $offset, $userid){
global $xoopsDB;
//處理許功蓋
if(get_magic_quotes_gpc()){
foreach($queryarray as $k=>$v){
$arr[$k]=addslashes($v);
}
$queryarray=$arr;
}
$sql = "SELECT sn,name,post_date, uid FROM ".$xoopsDB->prefix("contact")." WHERE 1";
if ( $userid != 0 ) {
$sql .= " AND uid=".$userid." ";
}
if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= " AND ((name LIKE '%{$queryarray[0]}%' OR company LIKE '%{$queryarray[0]}%' OR note LIKE '%{$queryarray[0]}%')";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "( name LIKE '%{$queryarray[$i]}%' OR company LIKE '%{$queryarray[$i]}%' OR note LIKE '%{$queryarray[$i]}%')";
}
$sql .= ") ";
}
$sql .= "ORDER BY name DESC";
$result = $xoopsDB->query($sql,$limit,$offset);
$ret = array();
$i = 0;
while($myrow = $xoopsDB->fetchArray($result)){
$ret[$i]['image'] = "images/arrow.gif";
$ret[$i]['link'] = "index.php?op=show&sn=".$myrow['sn'];
$ret[$i]['title'] = $myrow['name'];
$ret[$i]['time'] = strtotime($myrow['post_date']) ;
$ret[$i]['uid'] = $myrow['uid'];
$i++;
}
return $ret;
}
?>