I've been trying to get this sorted without success for a while so
if anyone can give me a hand I'd be more than grateful. I'm
setting up two pages on my localhost for all my favourite links
using two tables: links and topics.
Links:
links_id tinyint(5) unsigned NOT NULL auto_increment,
links_url varchar(250) NOT NULL default '',
links_description varchar(40) NOT NULL default '',
links_access set('local','remote') NOT NULL default '',
links_area smallint(3) unsigned NOT NULL default '1',
PRIMARY KEY (links_id)
Topics:
topics_id tinyint(5) unsigned NOT NULL auto_increment,
topics_area varchar(30) NOT NULL default '',
PRIMARY KEY (topics_id)
There are two pages: virtual.html (for all links on my computer)
and internet.html (for all online links). I want to pull the data from
the DB onto these two pages passing an argument $access to a
generic function. $access is either 'local' (for virtual.html) or 'remote' (for internet.html).
The problem is that when I pull the data I try to loop through the
array to get the individual links per topic area. All the topic areas
come up fine, however, only one topic per area shows up. Does
anyone have any idea what I'm getting wrong?
function links_menus($access)
{
$query = " SELECT links_url, links_description, topics_id, topics_area, links_area
FROM topics a
LEFT JOIN links b
ON a.topics_id = b.links_area
WHERE b.links_access = '$access'
GROUP BY a.topics_area
ORDER BY a.topics_area";
$result = mysql_query($query);
if (mysql_num_rows($result) > '0')
{
while($row = mysql_fetch_array($result))
{
echo "<form name=linksmenu>
<select name=newlocation>
<option>" . $row["topics_area"] . "</option>
<option>-----------------------------------------------------------------</option>
<option value=" . $row["links_url"] . ">" . $row["links_description"] . "</option>";
if (isset($previousareaname) && $previousareaname == $row["topics_id"])
{
echo "<option value=" . $row["links_url"] . ">" . $row["links_description"] . "</option>";
}
$previousareaname = $row["topics_id"];
echo "</select>
<input value=go type=button onclick=jumppage(this.form.newlocation)>
</form>";
}
mysql_free_result ($result);
}
}