c_pattle Posted August 30, 2010 Share Posted August 30, 2010 I was just wondering when you run a mysql query what the easiest way to find out the number of rows returned. Just so I can do a number of results found on a search. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/ Share on other sites More sharing options...
wildteen88 Posted August 30, 2010 Share Posted August 30, 2010 You'd use mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105292 Share on other sites More sharing options...
c_pattle Posted August 30, 2010 Author Share Posted August 30, 2010 Thanks. Is there a list of all of the php/mysql functions such as mysql_num_rows and mysql_fetch_array etc? Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105293 Share on other sites More sharing options...
mikosiko Posted August 30, 2010 Share Posted August 30, 2010 In case that you didn't notice... the name of the function that was provided to you is a link to the manual ... here is the whole link http://www.php.net/mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105297 Share on other sites More sharing options...
sasa Posted August 30, 2010 Share Posted August 30, 2010 http://php.net/manual/en/ref.mysql.php Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105299 Share on other sites More sharing options...
c_pattle Posted August 30, 2010 Author Share Posted August 30, 2010 Thank you. Also I have another question. At the moment this is my mysql query $data_sql = "select * from data limit 0, 24"; However I want to get the number of all of the rows in the table "data". There for should I run a the sql ="select * from data" and then use mysql_num_rows on the results of that query and store it in a variable? However surely this is a bad way of doing it because I am selecting all of the data from a database just to get the number of rows. Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105303 Share on other sites More sharing options...
sasa Posted August 30, 2010 Share Posted August 30, 2010 select COUNT(ID) AS num_of_rows from data this return just number of data (one row) Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105305 Share on other sites More sharing options...
DavidAM Posted August 30, 2010 Share Posted August 30, 2010 Or, if you have 5.0+ use select SQL_CALC_FOUND_ROWS * from data limit 0, 24 followed by another query SELECT FOUND_ROWS() The second query will return the number of rows that would have satisfied the previous query if the LIMIT was not present. $sql = "select SQL_CALC_FOUND_ROWS * from data WHERE categoryID = 4 limit 0, 24"; $resList = mysql_execute($sql); $resCnt = mysql_execute("SELECT FOUND_ROWS()"); $row = mysql_fetch_row($resCnt); $totalAvailable = $row[0]; while ($row = mysql_fetch_assoc($resList)) { // Show the data } echo "There are " . $totalAvailable . " records available for Category 4"; (I just threw the WHERE clause in to show that it can be used) Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105310 Share on other sites More sharing options...
c_pattle Posted August 30, 2010 Author Share Posted August 30, 2010 Cool, thanks for your replies. Quote Link to comment https://forums.phpfreaks.com/topic/212093-mysql-number-of-rows-returned/#findComment-1105312 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.