線上書籍

Home

[1071]XOOPS模組開發

<?php //搜尋程式 function snews_search($queryarray, $andor, $limit, $offset, $userid) { global $xoopsDB; $sql = "SELECT `sn`,`title`,`update_time`, `uid` FROM " . $xoopsDB->prefix("snews") . " WHERE 1"; if ($userid != 0) { $sql .= " AND uid=" . $userid . " "; } if (is_array($queryarray) && $count = count($queryarray)) { $sql .= " AND ((`title` LIKE '%{$queryarray[0]}%' OR `content` LIKE '%{$queryarray[0]}%' )"; for ($i = 1; $i < $count; $i++) { $sql .= " $andor "; $sql .= "(`title` LIKE '%{$queryarray[$i]}%' OR `content` LIKE '%{$queryarray[$i]}%' )"; } $sql .= ") "; } $sql .= "ORDER BY `update_time` DESC"; $result = $xoopsDB->query($sql, $limit, $offset); $ret = array(); $i = 0; while ($myrow = $xoopsDB->fetchArray($result)) { $ret[$i]['image'] = "images/icons/on.png"; $ret[$i]['link'] = "index.php?sn=" . $myrow['sn']; $ret[$i]['title'] = $myrow['title']; $ret[$i]['time'] = strtotime($myrow['update_time']); $ret[$i]['uid'] = $myrow['uid']; $i++; } return $ret; }