PHP Error FROM, LEFT JOIN, ON, WHERE old coding style?

Help.

New member
$albums_query = "select 'albums.album_id','albums.timestamp','albums.name', LEFT('albums.description', 50) as 'description', COUNT('images.image_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'
";

Is there anything wrong with this code?
It is trying to join 2 tables, that's all I know.
I think an old coding convention/coding style is used.

The full code is here.

function get_albums() {

$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatabase = "visualupload";

$link = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbdatabase);

$albums = array();
$albums_query = "select 'albums.album_id','albums.timestamp','albums.name', LEFT('albums.description', 50) as 'description', COUNT('images.image_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'
";

$result = mysqli_query($link, $albums_query) or die(mysqli_error($link));

while ($albums_row = mysqli_fetch_assoc($result)) {
$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;
}
 
You want "GROUP BY albums.album_id, albums.timestamp, albums.description": the GROUP BY will fail otherwise because it requires all fields that aren't sums or counts or other aggregated values. You might want other fields in there: Yahoo Answers has truncated the code so I can't see all of it (there appears to be at least one other field between timestamp and description in your SELECT statement, so if that's not an aggregated value then add that to the GROUP BY as well.
 
Back
Top