gotornot Posted February 15, 2013 Share Posted February 15, 2013 Hi All I have a DB with over 950,000 rows and i want to be able to count how many rows are in the table. The only trouble is a mysql_num_rows statement takes ages i need something a lot quicker. This is what im using crrently and it doesnt work. any help would be great. <?php $qx = "select count(*) FROM products"; //$qnx = mysql_query( "SELECT SQL_CALC_FOUND_ROWS `id` From `products`" ); //$qnx = mysql_query($qx); //$qx = "SELECT * FROM products"; $qxr = mysql_query($qx); $qxn = mysql_num_rows($qxr); echo $qxn; ?> Link to comment https://forums.phpfreaks.com/topic/274544-using-php-to-tell-me-how-many-rows-are-in-a-table/ Share on other sites More sharing options...
jazzman1 Posted February 15, 2013 Share Posted February 15, 2013 Well, we need to know what error(s) did you get? Have you ever used the mysql_error() function? Link to comment https://forums.phpfreaks.com/topic/274544-using-php-to-tell-me-how-many-rows-are-in-a-table/#findComment-1412715 Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 $qx = "select count(*) as num_rows FROM products"; Will return 1 row with 1 column called num_rows containing the number of rows. Link to comment https://forums.phpfreaks.com/topic/274544-using-php-to-tell-me-how-many-rows-are-in-a-table/#findComment-1412721 Share on other sites More sharing options...
requinix Posted February 16, 2013 Share Posted February 16, 2013 Are you saying that the query $qx = "select count(*) FROM products"; takes too long to execute? Link to comment https://forums.phpfreaks.com/topic/274544-using-php-to-tell-me-how-many-rows-are-in-a-table/#findComment-1412723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.