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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    row count in mysql

    first my codes
    PHP Code:
    $link     mysql_connect("localhost","root","123") or die (mysql_errno()."<br/>"mysql_error());
    $db     mysql_select_db("forum",$link) or die (mysql_errno()."<br/>"mysql_error()); 
    i can count rows using mysql console
    PHP Code:
    SELECT COUNT(*) FROM user 
    and i can count rows using following code

    [PHP]$result = mysql_query("SELECT * FROM user", $link);
    $num_rows = mysql_num_rows($result);

    echo "$num_rows Rows\n";

    why can not i count rows following ?

    PHP Code:
    echo mysql_query("SELECT COUNT(*) FROM user",$link); 
    its output is
    Code:
    Resource id #4
    [/QUOTE]

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    I think COUNT needs a GROUP clause...

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arnaud View Post
    I think COUNT needs a GROUP clause...
    ........................


  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You need to select the value from the first result with mysql_result():
    PHP Code:
    $result mysql_query("SELECT COUNT(*) FROM user"$link);
    $num_rows mysql_result($result0);
    echo 
    "$num_rows Rows\n" 


  •  

    Posting Permissions

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