######################################## # op_show ######################################## function op_show($sn="") { global $mysqli,$smarty,$TBL; if(!$sn)redirect_header("index.php",3000,"查詢選單資料錯誤!!"); #取得單筆記錄,可以寫成函數 #sn ofsn kind title sort enable url target col_sn content $sql = "select * from `{$TBL['name']}` where `sn`='{$sn}'"; //$mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $DBV = $result->fetch_assoc(); #過濾撈出資料 $DBV['sn'] = intval($DBV['sn']); //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp $DBV['title'] = htmlspecialchars($DBV['title'], ENT_QUOTES); // 轉換雙引號和單引號 $DBV['sort'] = intval($DBV['sort']); $DBV['enable'] = $DBV['enable'] ? "是":"<span style='color:red;'>否</span>"; $DBV['date'] = intval($DBV['date']); $DBV['date'] = date("Y-m-d H:i:s",$DBV['date']);//格式化日期 $DBV['kind'] = intval($DBV['kind']); $DBV['kind'] = get_show_kind_title($DBV['kind']);//取得類別標題 //取得類標題 $DBV['summary'] = htmlspecialchars($DBV['summary'], ENT_QUOTES); // 轉換雙引號和單引號 $DBV['summary'] = nl2br($DBV['summary']); //$DBV['content'] = ($DBV['content'], ENT_QUOTES); // 轉換雙引號和單引號 $DBV['content'] = $DBV['content']; #取得圖片src $col_name="prod"; $DBV['file_name'] = get_file_name_src($DBV['sn'],$col_name); $smarty->assign("DBV", $DBV); return; }
######################################## #取得類別標題 ######################################## function get_show_kind_title($sn="") { global $mysqli; if(!$sn)redirect_header("index.php",3000,"查詢選單資料錯誤!!"); $sql = "select title from `show_kind` where `sn`='{$sn}'"; //$mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $DBV = $result->fetch_assoc(); #過濾撈出資料 $DBV['title'] = htmlspecialchars($DBV['title'], ENT_QUOTES); // 轉換雙引號和單引號 return $DBV['title']; }