Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Practical php/mysql unlimited subcategories  (Read 9321 times)

bionicman

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 51
Practical php/mysql unlimited subcategories
« 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:
Logged