|
2#
樓主 |
發表於 2010-4-15 18:59:30
|
只看該作者
經過藍色小舖
的alight大大指導後
問題已解決
在php先做文章的分類...
smarty只幫你輸出...
php- $sql="SELECT * FROM net_class ORDER BY num ASC";
- $query=$db->query($sql);
- while ($row_class=$db->fetch_array($query))
- {
- $sm_class[]=array(
- "cid"=>$row_class[cid],
- "num"=>$row_class[num],
- "name"=>$row_class[name]
- );
- }
- //提取首頁文章資料
- $sql="SELECT * FROM net_state ORDER BY num ASC";
- $query=$db->query($sql);
- $sm_state=array();
- while ( $row_state=$db->fetch_array($query))
- {
- $sm_state[]=array(
- "cid"=>$row_state[cid],
- "num"=>$row_state[num],
- "subject"=>$row_state[subject],
- "content"=>$row_state[content]
- );
- }
- //判斷每篇文章屬於哪個類別
- foreach($sm_state as $idx => $item)
- {
- foreach($sm_class as $idx2 => $item2)
- {
- if($item["cid"]==$item2["cid"])
- {
- $data[$idx2][]=$item;
- break;
- }
- }
- }
- $smarty->assign("sm_class",$sm_class);
- $smarty->assign("data",$data);
複製代碼 section 裡面的name 就是他的索引,你兩個索引重複了,他當然撈不到資料
smarty- {section name="idx" loop=$sm_class}
- 我是類別標題 {$sm_class[idx].name}
- {section name="idx2" loop=$data[idx]}
- 我是文章標題 {$data[idx][idx2].subject}
- {/section}
- {/section}
複製代碼 |
|