線上書籍

Home

1041 XOOPS模組開發

<?php //搜尋程式 function tad_ebook_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 `page_sn`,`page_title`,`page_post_time`, `uid` FROM ".$xoopsDB->prefix("tad_ebook_page")." WHERE 1"; if ( $userid != 0 ) { $sql .= " AND uid=".$userid." "; } if ( is_array($queryarray) && $count = count($queryarray) ) { $sql .= " AND ((`page_title` LIKE '%{$queryarray[0]}%' OR `page_content` LIKE '%{$queryarray[0]}%' OR `page_author` LIKE '%{$queryarray[0]}%' OR `page_tag` LIKE '%{$queryarray[0]}%')"; for($i=1;$i<$count;$i++){ $sql .= " $andor "; $sql .= "(`page_title` LIKE '%{$queryarray[$i]}%' OR `page_content` LIKE '%{$queryarray[$i]}%' OR `page_author` LIKE '%{$queryarray[$i]}%' OR `page_tag` LIKE '%{$queryarray[$i]}%')"; } $sql .= ") "; } $sql .= "ORDER BY `page_post_time` DESC"; $result = $xoopsDB->query($sql,$limit,$offset); $ret = array(); $i = 0; while($myrow = $xoopsDB->fetchArray($result)){ $ret[$i]['image'] = "images/search.png"; $ret[$i]['link'] = "index.php?page_sn=".$myrow['page_sn']; $ret[$i]['title'] = $myrow['page_title']; $ret[$i]['time'] = strtotime($myrow['page_post_time']); $ret[$i]['uid'] = $myrow['uid']; $i++; } return $ret; } ?>