Lisa23 Posted September 15, 2010 Share Posted September 15, 2010 Hi i need to count the number items in an album now on the album i have create a field called count which counts the number items in that album but now i dnt knw how to update those as soon insert a item in the table item so i thought woul be possible to create a script that when insert data into item tables also update album table row count by adding one like update count with A now A equal row count ++1 any help on start of it if possible???/ Quote Link to comment https://forums.phpfreaks.com/topic/213525-insert-and-update-at-same-time-and-add/ Share on other sites More sharing options...
Lisa23 Posted September 16, 2010 Author Share Posted September 16, 2010 i tried like this but did not work any help please $sql = "INSERT INTO " .PHOTOS_TABLE. " ( photo_name, photo_date, photo_proper, photo_size, album_id ) VALUES ( '" .addslashes($photo_name). "', " .time(). ", '" .addslashes($key_name). "', " .intval($size). ", " .$album. " )"; $update_query="UPDATE albums set $count=count+'1' WHERE $count=count"; // total will be updated to total+number of new puppies added. mysql_query($update_query); Quote Link to comment https://forums.phpfreaks.com/topic/213525-insert-and-update-at-same-time-and-add/#findComment-1111507 Share on other sites More sharing options...
mikosiko Posted September 16, 2010 Share Posted September 16, 2010 Hi i need to count the number items in an album now on the album i have create a field called count which counts the number items in that album And why you want to do that?.... when a simple query counting the records in your photo_table while you are displaying the records from your album should do the job? Quote Link to comment https://forums.phpfreaks.com/topic/213525-insert-and-update-at-same-time-and-add/#findComment-1111512 Share on other sites More sharing options...
Lisa23 Posted September 16, 2010 Author Share Posted September 16, 2010 well each photos has an album id now if i count number photos in photos table how can i define count number of photo with id 1 and id 2 and id 3 then each one display on specific album like album digital number items 5 album media number item 7 how can i do that i know to caount all the items in the photo table bt how is gona diferentiate by the id number?? Quote Link to comment https://forums.phpfreaks.com/topic/213525-insert-and-update-at-same-time-and-add/#findComment-1111671 Share on other sites More sharing options...
mikosiko Posted September 16, 2010 Share Posted September 16, 2010 well SELECT a.album_id, COUNT(b.photo_id) As NPhotos FROM photos_album a, JOIN photos_table b ON a.album_id = b.album_id GROUP BY a.album_id maybe? Quote Link to comment https://forums.phpfreaks.com/topic/213525-insert-and-update-at-same-time-and-add/#findComment-1111675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.