The Ace Posted May 31, 2008 Share Posted May 31, 2008 I am trying to get my users online into a table. I have got this: <?php include "globals.php"; print "<h3>Users Online</h3> <table border='1' width='70%' class='table'> <tr> <th width='15%'>Number</th> <th width='35%'>Username</th> <td width='20%'>Last Action</th> </tr> <tr> <td>$cn=0;</td> <td>$q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); while($r=$db->fetch_row($q))</td> <td>{ $la=time()-$r['laston']; $unit="secs"; if($la >= 60) { $la=(int) ($la/60); $unit="mins"; } if($la >= 60) { $la=(int) ($la/60); $unit="hours"; if($la >= 24) { $la=(int) ($la/24); $unit="days"; } } $cn++; print "$cn. [url='viewuser.php?u={$r[']{$r['username']}[/url] ($la $unit) ";</td></tr></table> } $h->endpage(); ?> But, there is a problem with this line: $q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); Any ideas!? :-P Quote Link to comment Share on other sites More sharing options...
Spudinski Posted May 31, 2008 Share Posted May 31, 2008 Re: Users Online <td>$cn=0;</td> <td>$q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); That's never going to work, learn a bit about PHP before attempting to create scripts. http://www.w3schools.com/PHP/php_string.asp Quote Link to comment Share on other sites More sharing options...
Tonka Posted May 31, 2008 Share Posted May 31, 2008 Re: Users Online try this <?php include "globals.php"; print "<h3>Users Online</h3> <table width=30% cellspacing='1' class='table'>"; $cn=0; $q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); while($r=$db->fetch_row($q)) { $la=time()-$r['laston']; $unit="secs"; if($la >= 60) { $la=(int) ($la/60); $unit="mins"; } if($la >= 60) { $la=(int) ($la/60); $unit="hours"; if($la >= 24) { $la=(int) ($la/24); $unit="days"; } } $cn++; print "<tr><td>$cn. [url='viewuser.php?u={$r[']{$r['username']}[/url] ($la $unit) </td></tr>"; } print "</table>"; $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
The Ace Posted May 31, 2008 Author Share Posted May 31, 2008 Re: Users Online Thanks... :) Quote Link to comment Share on other sites More sharing options...
Tonka Posted June 2, 2008 Share Posted June 2, 2008 Re: Users Online no problem Quote Link to comment Share on other sites More sharing options...
The Ace Posted June 12, 2008 Author Share Posted June 12, 2008 Re: Users Online I forgot, whenever there are multiple users online, it shows this: Here is my code: (same as above, from Tonka) <?php include "globals.php"; print "<h3>Users Online</h3> <table width=30% cellspacing='1' class='table'>"; $cn=0; $q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); while($r=$db->fetch_row($q)) { $la=time()-$r['laston']; $unit="secs"; if($la >= 60) { $la=(int) ($la/60); $unit="mins"; } if($la >= 60) { $la=(int) ($la/60); $unit="hours"; if($la >= 24) { $la=(int) ($la/24); $unit="days"; } } $cn++; print "<tr align='center'><th>No.</th><th>User</th><th>Time Since Last Click</th></tr><tr align='center'><td>$cn.</td> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url]</td> <td>($la $unit)</td></tr>"; } print "</table>"; $h->endpage(); ?> I am so confuzzled!!! :? Quote Link to comment Share on other sites More sharing options...
Floydian Posted June 12, 2008 Share Posted June 12, 2008 Re: Users Online <?php include "globals.php"; print "<h3>Users Online</h3> <table width=30% cellspacing='1' class='table'><tr align='center'><th>No.</th><th>User</th><th>Time Since Last Click</th></tr>"; $cn=0; $q=$db->query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC"); while($r=$db->fetch_row($q)) { $la=time()-$r['laston']; $unit="secs"; if($la >= 60) { $la=(int) ($la/60); $unit="mins"; } if($la >= 60) { $la=(int) ($la/60); $unit="hours"; if($la >= 24) { $la=(int) ($la/24); $unit="days"; } } $cn++; print "<tr align='center'><td>$cn.</td> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url]</td> <td>($la $unit)</td></tr>"; } print "</table>"; $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
Spudinski Posted June 12, 2008 Share Posted June 12, 2008 Re: Users Online Now just to go into a bit more depth of what happened here(a common mistake), and to help others experiencing this problem... What happened there is a simple programming error, something was in the while loop that wasn't meant to, thus the output was not what we intended for the script. The column headings(th elements), were included within the loop, and was repeated each time the loop executed, but we only want the table cells to be repeated with different(dynamic) values each time. Here is a quicker example of what happened here: <?php echo '<table>'; while(condition) { echo '<tr> <th>Heading 1</th> <th>Heading 2</th> </tr> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr>'; } echo '</table>'; ?> To correct this, you need to remove the table headings(th elements) from the loop. This will stop from the table headings being repeated again. <?php echo '<table> <tr> <th>Heading 1</th> <th>Heading 2</th> </tr>'; while(condition) { echo '<tr> <td>Cell 1</td> <td>Cell 2</td> </tr>'; } echo '</table>'; ?> Quote Link to comment Share on other sites More sharing options...
The Ace Posted June 12, 2008 Author Share Posted June 12, 2008 Re: Users Online Thanks to both of you!!! :D Quote Link to comment Share on other sites More sharing options...
Floydian Posted June 12, 2008 Share Posted June 12, 2008 Re: Users Online You're welcome Ace ;) Spudinski, you explained it much better than I would have. lol I'm glad you did that ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.