Re: Help with algorithm

From: Date: Wed, 12 Dec 2001 14:04:18 +0000
Subject: Re: Help with algorithm
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-77437@lists.php.net to get a copy of this message
Make a recursive function which work on global var or on var passed on reference function rec($parent_id, &$the_parent_array){ /// select name, theme_id from some_table where par_id=$parent_id; while ($arr = mysql_fetch_assoc($res)){ $the_parrent_array[$arr['theme_id']]=array('name'=>$arr['name']); rec($arr['theme_id'],$the_parent_array[$arr['theme_id']']); } } $your_array = array(); rec(1,$your_array); HTH Regards, Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS ----- Original Message ----- From: "Cesar Cordovez" <ccordovez@alenet.com> To: "PHP" <php-general@lists.php.net> Sent: Wednesday, December 12, 2001 3:55 PM Subject: [PHP] Help with algorithm > Hi guys! > > For the last couple of hours I have been trying to solve this algorithm with > no avail. If someone has an idea on how to solve it it will be greatly > apreciated. > > The Problem: > > I have stored in a MySQL table the following: > > - > Databases:MySQL > Databases:MS SQL Server > Databases:Oracle > Databases:Informix > Databases:DB2 > Databases:DBMS > Databases:4th Dimension > Software:Photoshop > Software:Illustrator > Software:DreamWeaver > Software:Utilities:QuickTime > Software:Utilities:Movie Converter > Software:Utilities:Norton Utilities > Software:Languages:C++ > Software:Languages:Pascal > Software:Languages:Basic > Software:Languages:Real Basic > Software:Languages:FORTRAN > > --> etc. > > I need to convert this table into an hierarquical popupmenu for a HTML page > I'm working on. Something like this: > > <optgroup label="Databases"> > <option label="MySQL" value="MySQL"></option> > <option label="MS SQL Server" value="MS SQL > Server"></option> > <option label="Oracle" value="Oracle" ></option> > <option label="Informix" value="Informix" ></option> > <option label="DB2" value="DB2" ></option> > <option label="DBMS" value="DBMS" ></option> > <option label="4th Dimension" value="4th Dimension" > ></option> > </optgroup> > <optgroup label="Software"> > <option label="Photoshop" value="Photoshop"></option> > <option label="Illustrator" value="Illustrator"></option> > <option label="DreamWeaver" value="DreamWeaver"></option> > <optgroup label="utilities"> > <option label="QuickTime" value="QuickTime"></option> > <option label="Movie Converter" value="Movie > Converter"></option> > <option label="Norton Utilities" value="Norton > Utilities"></option> > </optgroup> > > --> etc. > > Any help will be apreciated. TIA. > > > > > Cesar Cordovez V. > ccordovez@alenet.com > (305) 461 0012 x202 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#77437) next »