homepage Welcome to WebmasterWorld Guest from 54.161.202.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Counting records in MySQL Database
Current method is undercounting
otem




msg:3343569
 11:16 pm on May 18, 2007 (gmt 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?

Thanks

 

LifeinAsia




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

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)

otem




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

Thank you so much,

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

Thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved