Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,774
    Thanks
    84
    Thanked 110 Times in 109 Posts

    Count users in database

    I am trying to do a simple count for users in the database. However it's adding 1 extra to the number. There are 15 accounts but it's displaying 16.
    Any ideas? Thanks

    PHP Code:
    $sQry "SELECT count(*) FROM users";
    $obQry mysql_query($sQry);
    $count 0;
    if (
    false !== $obQry && mysql_num_rows($obQry) == 1)
    {
        
    $record mysql_fetch_row($obQry);
        
    $count $record[0];


    Been a sign maker for 8 years. My business:
    American Made Signs

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,025
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    According to this code, you have 16, not 15. Iterate them to verify each is valid.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,774
    Thanks
    84
    Thanked 110 Times in 109 Posts
    This is what the database shows: Showing rows 0 - 14 ( 15 total, Query took 0.0029 sec)

    How would I check? I tried foreach and that doesn't work.
    Been a sign maker for 8 years. My business:
    American Made Signs

  4. #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,025
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    You'll need to query for the data; that's just a count. Then you simply iterate it in a while loop.
    That said, perhaps you're incrementing the $count somewhere else by one?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  5. #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    4,081
    Thanks
    3
    Thanked 506 Times in 494 Posts
    I'm going to guess you have two different databases or tables in one database and your php code is operating on one, while you are looking at a different one using your database management tool.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •