I'm currently trying to make a function to sort a list of links where it follows this scheme:
Category 1
--Link 1
--Link 2
Category 2
--Link 1
--Link 2
I have the databse scheme correct...yet I just can't get the loop to display it like above. It repeats the same link over and over...rather than moving onto the next category after it's done all the links n the previous category. Could you please help?
function makelinks($styleid,$type){
global $db, $n;
if($type=="single"){
$searchquery = "";
} elseif($type=="left"){
$searchquery = "AND menuside='1' ";
} elseif($type=="right"){
$searchquery = "AND menuside='2'";
}
$info_style = $db->query_first("SELECT linkformat,catformat,linkblockformat FROM hh_style WHERE id = '$styleid'");
$cat_query = $db->query("SELECT * FROM hh_links WHERE iscat='1' ".$searchquery."ORDER BY numorder ASC");
while($category = $db->fetch_array($cat_query)) {
$link_output .= str_replace("%name%", $category['name'], $info_style['catformat']);
$link_query = $db->query("SELECT * FROM hh_links WHERE islink='1' AND parentcat='".$category['id']."' ORDER BY numorder ASC");
while($link = $db->fetch_array($link_query)) {
$link_output .= str_replace("%name%", $link['name'], $info_style['linkformat']);
$link_output .= str_replace("%url%", $link['url'], $link_output);
$link_output .= str_replace("%target%", $link['target'], $link_output);
}
}
return $link_output;
}