一、程式
$kind = system_CleanVars($_REQUEST, 'kind', '', 'int');
//顯示類別 case "showKind": showKind($kind); break;
二、函數
#顯示類別底下的商品 function showKind($kind = "") { global $xoopsDB, $xoopsTpl,$module_name; if (!$kind) { redirect_header(XOOPS_URL, 3, "資料錯誤!!"); } #---- 過濾讀出的變數值 ---- $myts = MyTextSanitizer::getInstance(); $sql = "select a.sn,a.title,b.title as kind_title from " . $xoopsDB->prefix("cnu_show_prod") . " as a left join " . $xoopsDB->prefix("cnu_show_kind") . " as b on a.kind=b.sn where a.enable='1' and a.kind='{$kind}' order by a.`sort` desc,a.`date` desc "; //die($sql); //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項); $p_count = 9; $PageBar = getPageBar($sql, $p_count, 10); $bar = $PageBar['bar']; $sql = $PageBar['sql']; $total = $PageBar['total']; $bar = $total > $p_count ? $bar : ""; $xoopsTpl->assign("bar", $bar); $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); #----單檔圖片上傳 $subdir = "prod"; //子目錄(前後不要有 / ) $ugmUpFiles = new ugmUpFiles($module_name, $subdir); //實體化 $col_name = "prod"; //資料表關鍵字 $thumb = false ; //顯示縮圖 $rows = array(); while ($row = $xoopsDB->fetchArray($result)) { $row['sn'] = intval($row['sn']); $row['title'] = $myts->addSlashes($row['title']); $row['kind_title'] = $myts->addSlashes($row['kind_title']); $col_sn = $row['sn']; //關鍵字流水號 $row['prod'] = $ugmUpFiles->get_rowPicSingleUrl($col_name,$col_sn,$thumb); #----------------------------------- $rows[] = $row; $main['title'] = $row['kind_title']; } $main['rows'] = $rows; $xoopsTpl->assign("main", $main); }
三、樣板
<{if $op=="opList" or $op=="showKind"}>