Hello. I've been working on a PHP project but I have this error: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given inC:\xampp\htdocs\Soundflex\func\album.func.php on line 22 Here's my album.func.php code <?phpfunction album_data($album_id) { } function album_check($album_id) { } function get_albums() { $albums = array(); $albums_query = mysql_query(" SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`songs`.`song_id`) as `song_count` FROM `albums` LEFT JOIN `songs` ON `albums`.`album_id` = `songs`.`album_id' WHERE `albums`.`user_id` = ".$_SESSION['user_id']." GROUP BY `albums`.`album_id' "); while ($albums_row = 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['song_count'] ); } return $albums;} function create_album($album_name, $album_description) { $album_name = mysql_real_escape_string(htmlentities($album_name)); $album_description = mysql_real_escape_string(htmlentities($album_description)); mysql_query("INSERT INTO `albums` VALUES ('', '".$_SESSION['user_id']."', UNIX_TIMESTAMP(), '$album_name', '$album_description')"); mkdir('uploads/'.mysql_insert_id(), 0744); mkdir('uploads/thumbs/'.mysql_insert_id(), 0744);} function edit_album($album_id, $album_name, $album_description) { } function delete_album($album_id) { } ?> PHP: And here's my albums.php code just in case <?phpinclude 'init.php'; if(!logged_in()) { header('Location: index.php'); exit();} include 'template/header.php';?> <h3>Albums</h3> <?php$albums = get_albums(); if (empty($albums)) { echo "<p>You haven't created any albums yet!</p>";} else { foreach ($albums as $album) { echo '<p><a href="view_album.php?album_id=', $album['id']. '">', $album['name'], '</a> (', $album['count'], ' images) <br /> ', $album['description'], '...<br/> <a href="edit_album.php?album_id=', $album['id'], '">Edit</a> / <a href="delete_album.php?album_id=', $album['id'], '">Delete</a> </p>'; }} include 'template/footer.php';?> PHP: Thanks.
Your query is most likely failing. Replace: $albums_query = mysql_query(" SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`songs`.`song_id`) as `song_count` FROM `albums` LEFT JOIN `songs` ON `albums`.`album_id` = `songs`.`album_id' WHERE `albums`.`user_id` = ".$_SESSION['user_id']." GROUP BY `albums`.`album_id' "); with: if(!$albums_query = mysql_query(" SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`songs`.`song_id`) as `song_count` FROM `albums` LEFT JOIN `songs` ON `albums`.`album_id` = `songs`.`album_id' WHERE `albums`.`user_id` = ".$_SESSION['user_id']." GROUP BY `albums`.`album_id' ")) { die(mysql_error()); }
You need to figure out what error the query is throwing. mysql_fetch_array and ..._assoc are essentially the same function. Your query is returning an error or nothing at all so you cannot fetch an array from it.