MySQL
  Home arrow MySQL arrow Page 3 - Display Users Online Based On Page Viewing
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Display Users Online Based On Page Viewing
By: Stan Crawford
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2002-09-18

    Table of Contents:
  • Display Users Online Based On Page Viewing
  • Building The Script
  • The Code Explained (contd.)
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Display Users Online Based On Page Viewing - The Code Explained (contd.)


    (Page 3 of 4 )

    The next part of the code looks like this:

    $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");

    if(!($result)) {
    print "Useronline Select Error > ";
    }


    This PHP code and MySQL query selects the IP address from the database and looks at the current page that the user is browsing (PHP_SELF). We do it this way so as to display the number of users online in the next part of the script.

    The if statements in the past few clips of code are error checking statements. The exclamation point (!) simply represents NOT FOUND or NULL

    Continuing on, we have the following code:

    $user = mysql_num_rows($result);

    mysql_close();

    if($user == 1) {
    print("<b>$user</b> user online\n");
    } else {
    print("<b>$user</b> users online\n");
    }

    ?>


    The variable $user simply counts the number of rows left in the useronline table and this in turn represents the number of users that are currently online. Pretty simple right?

    Finally, our PHP code closes the MYSQL database connection and then pdisplays the number of users online using the print function. If only one user is online then the script will output "1 user online", however if there is more than one user online (for example, 5), then the script will output "5 users online".

    For the more advanced PHP coders out there, we could've used something like this instead of our if block:

    print "$user user" . ($user == 1 ? "" : "s") . " online";

    More MySQL Articles
    More By Stan Crawford


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT