sNews Forum

Previous sNews versions => sNews 1.5 Final => Programming => Topic started by: bionicman on April 24, 2007, 05:32:22 pm

Title: Practical php/mysql unlimited subcategories
Post by: bionicman on April 24, 2007, 05:32:22 pm
Hi there! :)

I'm trying to make simple unlimited categories code.

Somthing like this:

>home
>>terms
>>sitemap
>about
>>general
>>contact

Here's MySQL database structure:

id | name         | parent
-------------------------------
1  |  home   |  0
2  |  about   |  0
3  |  terms   |  1
4  |  sitemap   |  1
5  |  general   |  2
6  |  contact   |  2

And here's code:

Code: [Select]
$catid = $_GET['id'];

$sql  = "SELECT * FROM `test` WHERE `parent` = '". $catid ."';";
$sqlresult = mysql_query($sql) or die(mysql_error());

while($r = mysql_fetch_array($sqlresult)) {

echo $r['name'] ."
\n";

}
For example, if $catid is 1 it results terms and sitemap. but I want it to echo somthing like breadcrumbs:
home > terms and home > sitemap


Any ideas?  :rolleyes:
Title: Practical php/mysql unlimited subcategories
Post by: centered on May 17, 2007, 04:22:30 am
I found some links to help in your search for subcategories:

http://www.alternateinterior.com/2007/01/recursive-data-structures-in-php.html
http://www.dbazine.com/oracle/or-articles/tropashko4
http://www.thescripts.com/forum/thread2336.html
http://www.chipmunk-scripts.com/board/index.php?forumID=&ID=9331