Jump to content


count the number of entrys

  • Please log in to reply
1 reply to this topic

#1 AdrianR

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 12 March 2006 - 01:12 PM

Hi people.
Someone told me a few days ago how to count the number of entrys in a field but I can`t make it work.I want to count only the number of entrys with text"content" and "content2"
here is what I`ve done:

$s=SQLSELECT COUNT(field_name) FROM table_name where fieldname=content or fieldname=content2;
echo $s;

But it dosen`t work,I get errors.

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 12 March 2006 - 01:27 PM


$result=mysql_query("SELECT COUNT(field_name) FROM table_name");

echo mysql_result ($result,0,0);

To count those with specific values

$result=mysql_query("SELECT COUNT(*) FROM table_name
          WHERE (field_name = 'content1') OR (field_name = 'content2' ");
echo mysql_result ($result,0,0);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users