June 18, 2015

MySQL: why does "SELECT count()" return a value of array?




There are two solution to get total number of records from any table, Here are both explain in brief:


First one is - you can used COUNT() directly to select query like below e.g.

$Qr=mysql_query('select COUNT(*) from tablename');
$Qry=mysql_fetch_array($Qr);
echo $Qry;

It's display total number of records.

--------------------------


Second one is - 'mysql_num_rows' like below e.g.

$Qr=mysql_query('select * from tablename');
$Qry=mysql_num_rows($Qr);
echo $Qry;

It's display total number of records.



Enjoy!

No comments:

Post a Comment

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...