first off ill explain what im doing, im making a website and im using a mysql database to generate the links in the menu.
in the menu there will be category's which contain the links like the below:
CATEGORY 1
link 1
link 2
link 3
CATEGORY 2
link 1
link 2
link 3
i have tried to get all of the info needed by using a while loop, but it only seems to be getting 1 link from the database and it repeats it through all category's.
if you would like to see the results live, here it is:
http://www.designs.sketchfx.co.uk/index.php
heres my tables:
ive used a table to link 2 tables together, 1st contains the actual links and their names, 2nd contains the stuff to relate both tables and the third is the category names and their id's.



heres my script (its just a function):
Code: Select all
function display_menu(){
//get a list of categorys
$cats = @mysql_query('SELECT id, name FROM linkCategory');
if(!$cats){
echo '<p>error retreiving menu from' .
'<br /> the database</p>';
}
//get category name and id
while ($cat = mysql_fetch_array($cats)){
$name = $cat['name'];
$catid = $cat['id'];
//get corresponding links
$links = @mysql_query("SELECT linkid FROM linkcategory WHERE categoryid ='$catid'");
if(!$links){
echo '<p>error retreiving menu from' .
'<br /> the database</p>';
}
while($link = mysql_fetch_array($links)){
$linkid = $link['linkid'];
}
$actual_links = @mysql_query("SELECT name, url FROM menu WHERE id ='$linkid'");
while($actual_link = mysql_fetch_array($actual_links)){
$link_name = $actual_link['name'];
$link_url = $actual_link['url'];
}
echo "<h1>$name</h1>\n
<li><a href='$link_url'/>$link_name</a></li>\n";
}
}if anybody could help me at all i would be most great full