Re: help gurus: multi-dimensional array problem.

From: Date: Mon, 05 Mar 2001 14:38:36 +0000
Subject: Re: help gurus: multi-dimensional array problem.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42615@lists.php.net to get a copy of this message
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

« previous php.general (#42615) next »