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; ?> Quote 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? Quote 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. Quote 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? Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.