help gurus: multi-dimensional array problem.

From: Date: Sat, 03 Mar 2001 19:26:30 +0000
Subject: help gurus: multi-dimensional array problem.
Groups: php.general 
Request: Send a blank email to php-general+get-42465@lists.php.net to get a copy of this message
help! :)> I'm trying to return a list of links under associated categories from a database table that has the fields: "linkID, category, name, url". I'm selecting the fields and then trying to construct a multi-dimensional array so that the correct items get put into it (and then printed out): //connect to database, get results. $link_id = mysql_connect($host, $usr, $pass) or die (mysql_error()); mysql_select_db($database, $link_id); $sql="select category, name, url from links"; $result = mysql_query($sql, $link_id) or die ("no results"); //buil multi-dimensional array where $category[$name[$url]] while($row=mysql_fetch_array($result)) //read a row into array { extract($row); //populate $category, $name, $url variables $links = array($category => array($name, $url)); //build multi-D array. } // print list of categories with local anchors // and under each category print link name and url while (list($category) = each($links)) { echo ("<a href=\"$PHP_SELF?#$category\">$category</font></a>"); while (list($name, $url) = each ($links[$category])) { echo ("<a href=\"$url\">$name</a>"); } } right now this is only printing ONE category, and numerical index values that contain $name and $url at the same level. thanks for ANY suggestions! cheers, andrew

« previous php.general (#42465) next »