$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;
}
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;
}