Page 1 of 1
Counting the total number of the line in database
Posted: Sat Jul 02, 2005 2:55 pm
by mustafamisir
Hi all,
I am trying to count the total number of the line in database(MySQL)by this code;
Code: Select all
$tel_num = mysql_query("e;SELECT COUNT(*) FROM tel_detail"e;, $db);
The value of $tel_num must be 85, but it gives only 4.
How I can solve this problem?

Posted: Sat Jul 02, 2005 3:07 pm
by Chris Corbyn
Hmmm thats all wrong. What you nned to do is read the result using one of the mysql rsult functions. mysql_result() in this case is perfect.
Code: Select all
$result = mysql_query("SELECT COUNT(*) AS tot_rows FROM tel_detail", $db);
echo mysql_result($result, 0, 'tot_rows');
You might also wish to take a look at
mysql_num_rows()
Re: Counting the total number of the line in database
Posted: Sat Jul 02, 2005 9:31 pm
by trukfixer
mustafamisir wrote:Hi all,
I am trying to count the total number of the line in database(MySQL)by this code;
Code: Select all
$tel_num = mysql_query("e;SELECT COUNT(*) FROM tel_detail"e;, $db);
The value of $tel_num must be 85, but it gives only 4.
How I can solve this problem?

it gives 4 because that is the mysql result resource ID integer from mysql operation.
you might want to do:
Code: Select all
$tel_num = mysql_fetch_array(mysql_query("select count(*) as count from tel_detail",$db));
echo $tel_num['count'];