Hello Guys, i need your help. I can't understand what is wrong with the code. i am doing left join When i query in mysql it works fine, i can see that left join works and the image_count row is in the album table. when i do it on the server,trying to make an album it says :Query was empty; what's wrong here? function get_albums() { $albums = array(); $albums_query = mysql_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 "); $res = mysql_query($albums_query) or die(mysql_error()); while($albums_row = mysql_fetch_assoc($res)){ $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; } PHP: another file print_r(get_albums))
I'd start by changing the way you set up your query and your fail statement to $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"; $res = mysql_query($albums_query) or die(mysql_error().'<br>'.$albums_query); PHP: I think you'll find it magically comes right. If not, copy the query that gets echo'd out and put it into phpMyAdmin/SqlYog or whatever you use to manage your database.