ohdang888 Posted March 26, 2008 Share Posted March 26, 2008 I'm just wondering if there is much of a difference between COUNT in mysql and Mysql_num_row.... I heard the num_row is becoming outdated and is leff efficient... is that true? Thanks Link to comment https://forums.phpfreaks.com/topic/97892-which-is-better-count-or-num_row/ Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 if your purpose is to only count the rows use count but if you will count the number of data you are retrieving then you may use mysql_num_rows Link to comment https://forums.phpfreaks.com/topic/97892-which-is-better-count-or-num_row/#findComment-500863 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 I think COUNT and mysql_num_rows serve the same purpose for the most part. It just depends on what you're trying to accomplish IMO. I hear that MySQL is faster than PHP, so maybe there is something to using COUNT over mysql_num_rows, but I've never seen any testing data and wouldn't be able to even think about how you'd test that. I think it's mostly personal preference. I've done both in past. Usually I use mysql_num_rows just to check to see if I got any rows back and COUNT when I need a total for something. You can use COUNT when you need a total of something that appears in the database. But you can use mysql_num_rows for that as well. I keep saying this, but it just depends IMO. If you're checking how many rows got returned for whether or not you want to move into an if statement, obviously COUNT wouldn't work. Link to comment https://forums.phpfreaks.com/topic/97892-which-is-better-count-or-num_row/#findComment-501002 Share on other sites More sharing options...
Barand Posted March 26, 2008 Share Posted March 26, 2008 The speed of query largely affected by the amount of data returned by the query so fetching shed loads of data just to get the number of matching rows is plainly crazy. madness $res = mysql_query ("SELECT * FROM table"); echo mysql_num_rows($res); efficient (mysql doesn't even need to read the data in this case) $res = mysql_query ("SELECT COUNT(*) FROM table"); echo mysql_result ($res, 0); As mentioned earlier, if you need the returned rows for processing anyway, then use num rows. If you are aggregating totals with a GROUP BY, it has to be COUNT, not num rows. Nothing to do with num_rows being outdated. Link to comment https://forums.phpfreaks.com/topic/97892-which-is-better-count-or-num_row/#findComment-501015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.