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,447
    Thanks
    71
    Thanked 102 Times in 101 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 7 years. My business:
    American Made Signs

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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'); 

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 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 7 years. My business:
    American Made Signs

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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'); 

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,043
    Thanks
    2
    Thanked 316 Times in 308 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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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