php_begins Posted June 22, 2011 Share Posted June 22, 2011 Hello, I need to count the number of rows in my database which has images from different tables. I tried implementing it using the code below. But mysql_num_rows returns 0. Not sure if my approach is correct $getimagecounttotal=""; $getimagecount="(SELECT image_id FROM R1_REGISTRY_IMAGE ) UNION (SELECT image_id FROM R2_REVIEWS_IMAGE ) UNION (SELECT image_id FROM REGISTRY_IMAGE ) UNION (SELECT image_id FROM REVIEWS_IMAGE ) UNION (SELECT Photo_id FROM Photos )"; $getimagecount_results= mysql_query($getimagecount) or die(mysql_error()); $getimagecounttotal=mysql_num_rows($getimagecount); if($getimagecounttotal=="") { $getimagecounttotal="0"; } echo $getimagecounttotal; Link to comment https://forums.phpfreaks.com/topic/240148-return-number-of-rows-by-selecting-from-multiple-tables/ Share on other sites More sharing options...
requinix Posted June 22, 2011 Share Posted June 22, 2011 SELECT ( SELECT COUNT(*) FROM R1_REGISTRY_IMAGE ) + ( SELECT COUNT(*) FROM R2_REVIEWS_IMAGE ) + ( SELECT COUNT(*) FROM REGISTRY_IMAGE ) + ( SELECT COUNT(*) FROM REVIEWS_IMAGE ) + ( SELECT COUNT(*) FROM Photos ) AS count Then use any mysql_* function that fetches data from a resultset (not mysql_num_rows). Link to comment https://forums.phpfreaks.com/topic/240148-return-number-of-rows-by-selecting-from-multiple-tables/#findComment-1233538 Share on other sites More sharing options...
php_begins Posted June 22, 2011 Author Share Posted June 22, 2011 thanks for the reply, but any other mysql_fetch function still returns 0 in my case.. Link to comment https://forums.phpfreaks.com/topic/240148-return-number-of-rows-by-selecting-from-multiple-tables/#findComment-1233544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.