PHP SMARTY 双循环(递归)输出分类 问题
模版
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->{foreach from=$classlist item=newsclass} <div class="bg03"><a href="news.php?classid=%7B%24newsclass.id%7D&%7Bif%20%24newsclass.ispro%20eq%201%7Dispro=true%7B/if%7D" target="main">{$newsclass.classname}</a></div>{/foreach}
程序
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$sql = "select * from jh_newsclass where parentid = 0";$result = $mysqli->query($sql);while ($row = $result->fetch_row()) { $classlist[] = array( 'id'=>$row[0], 'classname'=>$row[2], 'parentid'=>$row[1], 'ispro'=>$row[3], );}$result->close();$mysqli->close();$smarty->assign('classlist',$classlist);$smarty->assign('webname',Webname);$smarty->display('admin/left.htm');
这样只能输出一级分类. 我需要在一级分类下再输出二级..三级..该怎么写呀?
以前用ASP输出的效果
- HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> <div class="bg03">新闻专题</div><div class="forumlist_groups"><div align="left"><ul> <li class="forumli"><a href="news.asp?classid=3&newsclass=3" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">新闻动态</font></a></li> <li class="forumli"><a href="news.asp?classid=6&newsclass=6" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">美大专题</font></a></li> <li class="forumli"><a href="news.asp?classid=16&newsclass=16" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">月兔专题</font></a></li> </ul></div></div> <div class="bg03"><a href="news.asp?classid=14&newsclass=14" target="main">供求信息</a></div> <div class="bg03">产品展示</div><div class="forumlist_groups"><div align="left"><ul> <li class="forumli"><a href="news.asp?classid=18&ispro=true&newsclass=18" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">美大灶具</font></a></li> <li class="forumli"><a href="news.asp?classid=19&ispro=true&newsclass=19" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">月图厨柜</font></a></li> <li class="forumli"><a href="news.asp?classid=20&ispro=true&newsclass=20" target="main">+--<img src="/static/imghwm/default1.png" data-src="images/leaf.gif" class="lazy" id="folder180" style="max-width:90%" style="max-width:90%" align="absmiddle" alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">集成效果</font></a></li> </ul></div></div>
原来的ASP代码
- HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> <div class="bg03"><a href="news.php?classid=<%=rs(" id>&newsclass=" target="main"></a></div> <div class="bg03"></div> <div align="left"><ul>") while not showparentclassrs.eof response.Write"<li class="" forumli>" set temprs = conn.execute("select * from Jh_newsclass where parentid = " & showparentclassrs("id")) if temprs.eof and temprs.bof then response.Write"<a href="news.php?classid=%22&showparentclassrs(%22id%22)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20showparentclassrs(%22ispro%22)%20then%20response.Write(%22&ispro=true%22)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20response.Write%22&newsclass=%22&showparentclassrs(%22id%22)&%22" target="main">" & astr & tree & "<img src="/static/imghwm/default1.png" data-src="" images class="lazy" id="" folder180 style="max-width:90%" height="" align="" absmiddle alt="PHP SMARTY 双循环(递归)输出分类 有关问题" ><font color="">" & showparentclassrs("classname")&"</font></a>" else response.Write astr & tree & "<img src="/static/imghwm/default1.png" data-src="" images class="lazy" id="" folder180 style="max-width:90%" height="" align="" absmiddle alt="PHP SMARTY 双循环(递归)输出分类 有关问题" >" & showparentclassrs("classname") end if set temprs = nothing response.Write"</li>" call showparentclass(astr,tree&"--",showparentclassrs("id")) showparentclassrs.movenext wend response.Write("</ul></div>") end ifend sub%><div class="clear"> </div>

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。