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:[EMAIL PROTECTED]]
> Sent: 03 March 2001 19:59
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> 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, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
> 
> > Addressed to: andrew <[EMAIL PROTECTED]>
> >             [EMAIL PROTECTED]
> > 
> > ** Reply to note from andrew <[EMAIL PROTECTED]> 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
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to