Links In Category Help!!!
Posted: Fri Aug 22, 2003 1:51 am
Hey!
I have a links directory and need to calculate the number of links in a category and it's subcaetgroies and so on.
I tried this:
That's supposed to get the links in the first category, then select the amount of links in their sub categories and so on until I get all the links in the category and its categories.
Im not all that good with functions or adding numbers this way...
Any ideas?
Thanks
I have a links directory and need to calculate the number of links in a category and it's subcaetgroies and so on.
I tried this:
Code: Select all
<?php
function links($cat) {
global $tbl_name;
$select_pcats = "select cat from ".$tbl_name."_cats where parent='$cat'";
$select_pcats_result = mysql_query($select_pcats) or die("<b>MySQL Error:</b> " . mysql_error());
$rows = mysql_num_rows($select_pcats_result);
for($c=0;$c<$rows;$c++) {
$resrow = mysql_fetch_row($select_pcats_result);
$pcatsid = $resrow[0];
$linkscount = mysql_fetch_array(mysql_query("select count(*) as links from ".$tbl_name."_links where cat='$pcatsid'"));
$otherlinks .= $linkscount[links] . '+';
links($pcatsid);
}
return $otherlinks;
}
$cat = "0";
$links = mysql_fetch_array(mysql_query("select count(*) as links from ".$tbl_name."_links where cat='$cat'"));
$links = $links[links] + $otherlinks;
links($cat);
?>Im not all that good with functions or adding numbers this way...
Any ideas?
Thanks