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)

Junior Member

10+ Year Member

joined:Feb 6, 2007
votes: 0

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)

Moderator from US 

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

joined:Dec 10, 2005
votes: 76

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)

Junior Member

10+ Year Member

joined:Feb 6, 2007
votes: 0

Thank you so much,

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



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members