最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

PHP站點(diǎn)地圖函數(shù)

PHP站點(diǎn)地圖函數(shù)

PHP
慕尼黑8549860 2023-05-12 15:30:35
和往常一樣,過去幾個(gè)小時(shí)我都在這上面花了,但無法找到更好的方法。我有一個(gè) CMS,需要?jiǎng)?chuàng)建站點(diǎn)地圖。我有作品的功能,但很亂,不太適合用途,想知道是否有人有任何建議。我在下面有 for 循環(huán)和類似的東西,但我還不是所有的人都知道如何使用它們。我已經(jīng)包括了我已經(jīng)擁有的功能以及數(shù)據(jù)庫的演示。tbl_website_posts| ID  | Title             | Parent ID ||-----|-------------------|-----------|| 1   | Parent 1          | 0         || 2   | Parent 2          | 0         || 3   | Child of 2        | 2         |該功能也非常有限,只能容納這么多孩子。如果有人對我可以從哪里開始提出建議,那就太棒了。預(yù)先感謝您的寶貴時(shí)間。
查看完整描述

1 回答

?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

我會(huì)為此使用遞歸函數(shù)。


function generate_sitemap($site_id, $parent_id=0) {

? ? global $dbcon;

? ? $return = '';


? ? $query = mysqli_query($dbcon, "SELECT * FROM tbl_website_posts WHERE post_website='$site_id' AND post_parent='$parent_id'");


? ? // side note: once you get this working it will be worth the effort to turn

? ? // this query into a prepared statement. Using variables in your query like

? ? // this puts you at risk of a SQL injection attack.


? ? if (mysql_num_rows($query) > 0) {

? ? ? ? $return = '<ul>';

? ? ? ? $icon = array('page' => 'fa-file-word', 'post' => 'fa-newspaper', 'event' => 'fa-calendar-star', 'calander' => 'fa-calendar-alt', 'training' => 'fa-award', 'people' => 'fa-user-alt', 'group' => 'fa-users-class');


? ? ? ? while ($array = mysqli_fetch_array($query, MYSQLI_ASSOC)) {

? ? ? ? ? ? $return .= '<li data-jstree=\'{"icon":"fal ' . $icon[$array['post_type']] . '"}\'>' . $array['post_title'];


? ? ? ? ? ? $return .= generate_sitemap($site_id, $array['id']);


? ? ? ? ? ? $return .= '</li>';

? ? ? ? }


? ? ? ? $return .= '</ul>';?

? ? }


? ? return $return;

}

所以基本上,開始時(shí)假設(shè)父頁面沒有任何子頁面(初始$return值為空字符串,所以我們不返回空值<ul></ul>)。


僅當(dāng)有孩子時(shí),才開始構(gòu)建<ul>所有子頁面。


在<li>子頁面的內(nèi)部,讓函數(shù)調(diào)用自身,并將孩子的 ID 作為新的父 ID。如果孩子沒有子頁面,嵌套函數(shù)調(diào)用將返回一個(gè)空字符串。否則,它將返回 a<ul>及其所有子項(xiàng)。


查看完整回答
反對 回復(fù) 2023-05-12
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)