Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Counting records in MySQL Database

Current method is undercounting



11:16 pm on May 18, 2007 (gmt 0)

5+ Year Member

Hello, using PHP and MySQL I'm trying to count from my database how many file modifications there have been.

In my database, I have user id's, file names, and number of modifications, looking something like this:

User, File, Modifications

Bob, file1.txt, 2
Kat, file1.txt, 0
Sam, file2.txt, 1
Bob, file3.txt, 4
Ron, file3.txt, 2

In total there have been 9 modifications. Unfortunatly my code only counts 4 using my current method.

This is the code I'm using:

$changes=mysql_num_rows(mysql_query("SELECT id FROM files WHERE modifications>0"));

I know this is wrong, but how better would I write this statement?



11:26 pm on May 18, 2007 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

My understanding is that mysql_num_rows returns the number of rows found, which will almost never be what you want.

Try the following query instead:
SELECT SUM(Modifications)


4:40 pm on May 20, 2007 (gmt 0)

5+ Year Member

Thank you so much,

I knew it just a short statement, but for the life of me I couldn't figure it out.



Featured Threads

Hot Threads This Week

Hot Threads This Month