jamesjmann Posted April 16, 2015 Share Posted April 16, 2015 Is there a way to get the count of rows like this? $count = somefunctionthatreturnscount(mysqli_query($mysqli, "SELECT COUNT(*) FROM table")); Instead of... $count = mysqli_num_rows(mysqli_query($mysqli, "SELECT id FROM table")); //or even... $count = mysqli_fetch_array(mysqli_query($mysqli, "SELECT COUNT(*) as count FROM table")); Ultimately, I want the method that will get the count the quickest and if can be done similarly to the first code and still have good performance. Thanks in advance! Update: Reported post as duplicate. Need moderate to delete duplicates as that option is not appearing for me. Link to comment https://forums.phpfreaks.com/topic/295611-fastest-way-to-count-mysql-rows-using-mysqli-or-another-method/ Share on other sites More sharing options...
Barand Posted April 16, 2015 Share Posted April 16, 2015 I use $res = $mysqli->query("SELECT COUNT(*) FROM table"); list($count) = $res->fetch_row(); Link to comment https://forums.phpfreaks.com/topic/295611-fastest-way-to-count-mysql-rows-using-mysqli-or-another-method/#findComment-1509198 Share on other sites More sharing options...
jamesjmann Posted April 16, 2015 Author Share Posted April 16, 2015 I use $res = $mysqli->query("SELECT COUNT(*) FROM table"); list($count) = $res->fetch_row(); This works, thank you! Link to comment https://forums.phpfreaks.com/topic/295611-fastest-way-to-count-mysql-rows-using-mysqli-or-another-method/#findComment-1509203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.