0

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

I have checked the code twice and I have also checked the titles in the table also and they match, I have probably been looking at the code for too long and it may be hard for me to find the error.

Lines 13-34

$albums_query = mysql_query("
SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT         (`images`.`images_id`) as `image_count`
FROM `albums`
LEFT JOIN `images`
ON `albums`.`album_id` = `images`.`album_id`
WHERE `albums`.`user_id` = ".$_SESSION['user_id']."
GROUP BY `albums`.`album_id` 
");

while ($albums_query = mysql_fetch_assoc($albums_query)) {
    $albums[] = array(
        'id' => $albums_row['album_id'],
        'timestamp' => $albums_row['timestamp'],
        'name' => $albums_row['name'],
        'description' => $albums_row['description'],
        'count' => $albums_row['image_count']
    );
}

return $albums ;

}

Community
  • 1
  • 1
hammy78
  • 27
  • 1
  • 6
  • (In general: stop using the mysql_* functions, they are being deprecated. Use mysqli or PDO instead.) Check the return values of your queries. In this case, try: `$query_text = "SELECT .... "; $query = mysql_query($query_text); if($query === false) { throw new Exception("Query Error: " . mysql_error() . " when trying to execute query: " . $query_text); }` – DCoder Apr 21 '12 at 16:40

1 Answers1

2

You're overriding your query result with a row of data:

$albums_query = mysql_fetch_assoc($albums_query)

Should be:

 $albums_row = mysql_fetch_assoc($albums_query)

(probably)

Halcyon
  • 56,029
  • 10
  • 87
  • 125
  • Even with this I still get the same error. – hammy78 Apr 21 '12 at 16:27
  • Then the original value of `$albums_query` is also not a MySQL resource. The most common explanation for that is that your query fails. Check with `mysql_error()`. – Halcyon Apr 21 '12 at 16:37