Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Hierarchical categories browser Jump to:  
Category: >> PHP Code >> Hierarchical categories browser Bookmark and Share

<< lastnext >>

Snippet Name: Hierarchical categories browser

Description: A very simple way to build and do a hierarchical HTML categories browser without javascript- just HTML, PHP and mySql.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?PHP
 
/* 
# 
# Table structure for table 'res_cat' 
# 
 
CREATE TABLE res_cat ( 
   ID int(32) DEFAULT '0' NOT NULL , 
   ID_uname char(40) NOT NULL, 
   UNIQUE ID (ID) 
); 
 
# 
# Dumping data for table 'res_cat' 
# 
 
INSERT INTO res_cat VALUES( '1', 'head1'); 
INSERT INTO res_cat VALUES( '101', 'cat11'); 
INSERT INTO res_cat VALUES( '102', 'cat12'); 
INSERT INTO res_cat VALUES( '103', 'cat13'); 
INSERT INTO res_cat VALUES( '10101', 'subcat111'); 
INSERT INTO res_cat VALUES( '10102', 'subcat112'); 
INSERT INTO res_cat VALUES( '10103', 'subcat113'); 
INSERT INTO res_cat VALUES( '1010101', 'subcat1111'); 
INSERT INTO res_cat VALUES( '1010102', 'subcat1112'); 
INSERT INTO res_cat VALUES( '1010103', 'subcat1113'); 
INSERT INTO res_cat VALUES( '10201', 'subcat121'); 
INSERT INTO res_cat VALUES( '10202', 'subcat122'); 
INSERT INTO res_cat VALUES( '10203', 'subcat123'); 
INSERT INTO res_cat VALUES( '10301', 'subcat131'); 
INSERT INTO res_cat VALUES( '10302', 'subcat132'); 
INSERT INTO res_cat VALUES( '10303', 'subcat133'); 
INSERT INTO res_cat VALUES( '2', 'head2'); 
INSERT INTO res_cat VALUES( '201', 'cat21'); 
INSERT INTO res_cat VALUES( '202', 'cat22'); 
INSERT INTO res_cat VALUES( '203', 'cat33'); 
etc ... 
*/ 
$mysql_link = MYSQL_CONNECT("localhost", "user", "passwd"); 
MYSQL_SELECT_DB("res_cat", $mysql_link); 
ECHO "<html><body>" ; 
 
FUNCTION listrub ($id , $exploseID   ) 
{ 
GLOBAL $PHP_SELF ; 
GLOBAL $mysql_link  ; 
$maxi = ($id*100)+100 ; 
$mini = $id*100 ; 
$query = "SELECT * FROM res_cat  where ID < $maxi and ID >  $mini    " ;   
ECHO "<ol>"; 
IF(      $mysql_result = MYSQL_QUERY($query , $mysql_link)   ) 
{ 
WHILE ($row = MYSQL_FETCH_OBJECT($mysql_result)) 
    { 
// you have to link some action on leaves of course 
ECHO "<li> <a href='$PHP_SELF?ID_rub=$row->ID' >   $row->ID_uname </a>  </li> " ; 
$testID = ($exploseID - ($exploseID  %100 ))/100 ; //  WARNING this is ugly .. only 3 level 
IF ( $testID == $row->ID || $exploseID == $row->ID) 
         { 
         listrub ($row->ID , $exploseID ) ; 
        } 
    } 
} 
ECHO "</ol>"; 
} 
$father =999999999;  // a big number   
// get the grand...grand father 
IF ( $ID_rub >100 ) 
{ 
$father = $ID_rub ; 
WHILE ( $father >100 )    { $father= ( $father - ( $father %100) )/100 ; } 
} 
ELSE{$father= $ID_rub ;} 
listrub ($father , $ID_rub ,$mysql_link ) ;   
ECHO "</body></html>"; 
 
?> 
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 72 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?