一、套用商品
select * from `ugm_show_prod` where `enable`='1'別名查詢
select a.* from `ugm_show_prod` as a where a.`enable`='1'選擇欄位
select a.`sn`,a.`title`,a.`summary` from `ugm_show_prod` as a where a.`enable`='1'跨表查詢
select a.`sn`,a.`title`,a.`summary`,b.`file_name`,b.`sub_dir` from `ugm_show_prod` as a left join `ugm_show_files_center` as b on a.sn=b.col_sn and b.col_name='prod' where a.`enable`='1'
########################################################### # 撈商品資料 ########################################################### function get_prod() { global $db, $smarty; #撈商品資料 $sql = "select a.`sn`,a.`title`,a.`summary`,b.`file_name`,b.`sub_dir` from `ugm_show_prod` as a left join `ugm_show_files_center` as b on a.sn=b.col_sn and b.col_name='prod' where a.`enable`='1' order by a.`sort` desc ";//die($sql); $result = $db->query($sql) or redirect_header("", 3000, $db->error."\n".$sql,true); $rows=[]; while($row = $result->fetch_assoc()){ #過濾資料 $row['sn'] = intval($row['sn']); $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); $row['summary'] = htmlspecialchars($row['summary'], ENT_QUOTES); $row['file_name'] = htmlspecialchars($row['file_name'], ENT_QUOTES); $row['sub_dir'] = htmlspecialchars($row['sub_dir'], ENT_QUOTES); $row['pic'] = ""; if($row['file_name']){ $row['pic'] = WEB_URL."/uploads/{$row['sub_dir']}/" . $row['file_name']; } $rows[] = $row; } //print_r($rows);die(); $smarty->assign("prods", $rows);//送至樣板 }
<{foreach from=$prods item=row}> <div class="col-lg-4 col-sm-6"> <a class="portfolio-box" href="<{$row.pic}>"> <img class="img-fluid" src="<{$row.pic}>" alt="<{$row.title}>"> <div class="portfolio-box-caption"> <div class="portfolio-box-caption-content"> <div class="project-category text-faded"> <{$row.title}> </div> <div class="project-name"> <{$row.summary}> </div> </div> </div> </a> </div> <{/foreach}>