Tim Ward wrote:
> 
> 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
> 

Hello,

This sulution is not very good: too many SELECTs, too much memory
usage...

Why not just use 2 Tables: Category and Links, and work with a LEFT
JOIN? Then you could get all data needed with a single SQL statment, no
additional arrays would be needed, either. Don't forget: MySQL is a
RELATIONAL database - Why not make usage of it?

Robert

-- 
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