新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHP中怎么實(shí)現(xiàn)一個(gè)無限級分類-創(chuàng)新互聯(lián)
PHP中怎么實(shí)現(xiàn)一個(gè)無限級分類,很多新手對此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
數(shù)據(jù)庫結(jié)構(gòu):
CREATE TABLE IF NOT EXISTS `city` ( `id` int(11) NOT NULL auto_increment, `name` varchar(30) character set utf8 collate utf8_unicode_ci NOT NULL default '0', `parentId` int(11) NOT NULL default '0' PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
php文件:
$db=new DB($Config['host'],$Config['user'],$Config['password'],$Config['port'],$Config['db'],$Config['charset']); function findCity($table,$id=0,$level=1){ global $db; $findSql="select id,name,parentId from $table where parentId={$id} order by id"; $findResult=$db->getArray($findSql); $num=$db->numRows; $logoStr="|"; for($i=0;$i<$level;$i++){ $logoStr.="--"; } if($num!=0){ for($j=0;$j<$num;$j++){ echo ""; findCity($table,$findResult[$j]['id'],$level+1); } } } findCity(city);
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。
網(wǎng)頁題目:PHP中怎么實(shí)現(xiàn)一個(gè)無限級分類-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://ef60e0e.cn/article/hcooi.html