I have a class that has two functions. the first will return a list of categories in links and also attempt to put the category ids from the mysql_fetch_array() function into a new array to store all the ids.
The second function attempts to create a new array which contains the total amount of users assigned to a category based on the array of ids that were previously stored.
Basically in the users table the is a field called cat_id which is the id of the category they are assigned to. So i need to count how many users with the same cat id exist for all categories.
Anyway here is my PHP. The returning of category links are fine, but the attempt at storing the ids is not. I suppose im trying to create a multi-dimensional array??
<?php
require_once("database.php");
class category extends database{
var $listCatNum = array();
var $totalAmountUsers = array();
// lists all the categories in a link
function catlist(){
$query = $this->query("select * from category order by Name asc");
while($listCat = $this->fetchArray($query)){
$thecategory .= "<a class=\"dir_link\" href=\"index.php?id=".$listCat[0]."\">".$listCat[1]."</a>\n";
// create an array of IDs so that i can work out total amount of users in a cat in function below.
$this->listCatNum[$listCat[0]];
}
return $thecategory;
}
// works out how many users are assigned to a category.
function catAmount(){
foreach($this->listCatNum as $totalUserId){
foreach($totalUserId as $totalUsers){
$q = $this->query("select count('Cat_ID') from user where Cat_ID={$totalUsers}");
$result = $this->fetchArray($q);
$this->totalAmountUsers[$result];
}
}
return $this->totalAmountUSers;
}
}
?>