Re: Job interview test - I give up...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



/*
	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.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux