Counting the total number of the line in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mustafamisir
Forum Newbie
Posts: 23
Joined: Wed Jun 22, 2005 1:00 pm
Contact:

Counting the total number of the line in database

Post 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(&quote;SELECT COUNT(*) FROM tel_detail&quote;, $db);
The value of $tel_num must be 85, but it gives only 4.
How I can solve this problem? :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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()
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Re: Counting the total number of the line in database

Post 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(&quote;SELECT COUNT(*) FROM tel_detail&quote;, $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'];
Post Reply