Re: Job interview test - I give up...
| From: | Raymond Chua Sing | Date: | Wed, 01 Dec 2004 14:08:07 +0000 |
| Subject: | Re: Job interview test - I give up... | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37490@lists.php.net to get a copy of this message | ||
/*
NOTE: this is what I came up with though I don't have the time to test it.
I think theres another way to solve this just by using a different
sql statement.
*/
function getNumDvdsInCategories() {
$query = "SELECT ca_id , ca_name FROM categories, dvds WHERE dv_caid = ca_id";
$results = mysql_query($query);
$counter = 0;
$counter2 = 0;
$oldflag = "";
$newflag = "";
while($row = mysql_fetch_assoc($results)) {
if(strcmp($row["ca_id"],$categories[$counter][ca_id]) == 0) {
//check if ca_id repeats
$counter2++; //if ca_id repeats it means we're still in the same
category but different dvd
} else {
//if ca_id changes it means we changed categories now.
$categories[$counter][num] = $counter2; //counter2 is the no. of
dvds in the category
$counter++; //goto the next array index for the next category
$counter2 = 0; //reset counter2
}
//self explanatory
$categories[$counter][ca_id] = $row["ca_id"];
$categories[$counter][ca_name] = $row["ca_name"];
}
return $categories;
}
-- There's only one basic human right, the right to do as you damn
well please. And with it comes the only basic human duty, the duty to
take the consequences.