RE: [PHP] help gurus: multi-dimensional array problem.

From: Date: Mon, 05 Mar 2001 12:35:48 +0000
Subject: RE: [PHP] help gurus: multi-dimensional array problem.
Groups: php.general 
Request: Send a blank email to php-general+get-42608@lists.php.net to get a copy of this message
Get a list of unique categories then get a list of each one would do it. $link_id = mysql_connect($host, $usr, $pass) or die (mysql_error()); mysql_select_db($database, $link_id); $sql="select distinct category from links"; $result = mysql_query($sql, $link_id) or die ("no results"); $cat_list = new Array(); while ($row=mysql_fetch_array($result)) { $cat_list[] = $row["category"]; echo("<a href=\"$PHP_SELF?#$category\">$category</font></a><br>"); }; foreach ($cat_list as $this_Cat) { echo("<a name=\"$category\">$this_Cat</font></a><br>"); $sql="select name, url from links where category = '$this_Cat'"; $result = mysql_query($sql, $link_id); while ($row=mysql_fetch_array($result)) { echo ("<a href='" . $row[url] . "'>" . $row["name"] . "</a><br>"); }; } haven't tested this but the principal should be okay and do what you're after Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -----Original Message----- > From: andrew [mailto:andrew@salamander.net] > Sent: 03 March 2001 19:59 > To: php3@developersdesk.com; php-general@lists.php.net > Subject: Re: [PHP] help gurus: multi-dimensional array problem. > > > Because I want to display it like this: > > > category1 (href anchor to category1 below) > category2 > category3 > > > category1 > link1 > link2 > link3 > > category2 > link1 > etc... > > > > On 3/3/01 2:49 PM, "php3@developersdesk.com" <php3@developersdesk.com> > wrote: > > > Addressed to: andrew <andrew@salamander.net> > > php-general@lists.php.net > > > > ** Reply to note from andrew <andrew@salamander.net> Sat, > 03 Mar 2001 14:26:30 > > -0500 > >> > >> 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): > >> > > > > Why build an array, and store ANOTHER copy of all the data in memory > > while the script runs? That is just a waste of memory... > > > > > > SELECT Category, Name, URL FROM Links ORDER BY Category, Name; > > > > > > > > To display them: > > > > $OldCategory = ''; > > > > while( list( $Category, $Name, $URL ) = mysql_fetch_row( > $Result )) { > > > > if( $OldCategory != $Category ) { > > print "Category Header $Category<BR>\n"; > > > > $OldCategory = $Category; > > } > > > > print "<A href=\"$URL\">$Name</a><BR>\n"; > > } > > > > > > > > > > > > Rick Widmer > > Internet Marketing Specialists > > http://www.developersdesk.com > >

« previous php.general (#42608) next »