SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: row count

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    row count

    Cant get a code that works on google, but can someone supply me witha quick code to code output the number of rows in the onlineusers table?
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select count(*) from onlineusers

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm something like this?

    <?php
    include "conf/db_connect.php";

    $query4 = mysql_query("select count(*) from onlineusers ")
    or die("Could not insert data because ".mysql_error());
    $qry4 = mysql_fetch_array( $query4 );

    echo "e $qry4[UserName]";
    ?>
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    i don't do php but that's not gonna work

    the SELECT COUNT(*) query returns only one column, the count

    typically, you would give the count a column alias so that you can refer to the column in your php code --
    Code:
    SELECT COUNT(*) AS daCount FROM onlineusers
    and then display whatever is in daCount

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm still cant get it to work
    Animated Chatrooms - www.121chatrooms.net

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $row mysql_fetch_array$query4 );

    echo 
    $row['daCount']; 
    // or without column alias: 
    echo $row['count(*)']; 
    or just
    PHP Code:
    // first row, first column
    echo mysql_result($query40); 


Bookmarks

Posting Permissions

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