Hello!
I’m trying to pull off the largest index for a particular group (the $user_id’s each have several $course_id’s associated with them). I’m using the following PHP/SQL to get the info from my database:
function getlastCourseTaught($read,$user_id) {
$sql = "SELECT MAX(course_id)
FROM courses
WHERE user_id = $user_id";
return $read->fetchAll($sql);
}
The code works but I’m having problems getting at the actual ID. When I print_r my results, I get:
Array ( [0] => Array ( [MAX(course_id)] => 1 ) )
So, two questions:
- Why is SQL giving me back an array? Doesn’t the MAX just return one specific number?
- How can I untangle the “array within the array” to get at the MAX(course_id) of “1”.
Thanks!
-Eric
PS IF this thread is more of a PHP question, please move it by all means.