runnerjp Posted June 25, 2008 Share Posted June 25, 2008 ok currently i have this <?php $result = mysql_query("SELECT * FROM useronline WHERE(file='http://www.runningprofiles.com/members/index.php?page=mainforum')"); while($row = mysql_fetch_array( $result )) { $last_active = time() - $row['timestamp']; $onlineuser = $row['user']; } if($last_active < 300) { echo $onlineuser; } ?> which should get all the users that are viewing the page http://www.runningprofiles.com/members/index.php?page=mainforum' but i really want to get all the users on my profile which has pages suck as http://www.runningprofiles.com/members/index.php?page=forum&forum=general http://www.runningprofiles.com/members/index.php?page=forum&forum=races but how can i also add these into the query Quote Link to comment Share on other sites More sharing options...
JakeSilver Posted June 25, 2008 Share Posted June 25, 2008 Use "OR" i.e. mysql_query("SELECT * FROM useronline WHERE(file='http://www.runningprofiles.com/members/index.php?page=mainforum') OR (file=' http://www.runningprofiles.com/members/index.php?page=forum&forum=general') OR ('http://www.runningprofiles.com/members/index.php?page=forum&forum=races'") that should work Quote Link to comment Share on other sites More sharing options...
DoddsAntS Posted June 25, 2008 Share Posted June 25, 2008 Something along the lines of SELECT * FROM useronline WHERE file IN ('http://www.runningprofiles.com/members/index.php?page=mainforum','http://www.runningprofiles.com/members/index.php?page=general')" You can add as many pages to the list as you want Quote Link to comment Share on other sites More sharing options...
JakeSilver Posted June 25, 2008 Share Posted June 25, 2008 Can't use "IN" as far as im aware "IN" isn't a MySQL Operator Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 humm ok i need to go back 1 step first... i used the simple part <?php $result = mysql_query("SELECT * FROM useronline WHERE(file='http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum')"); while($row = mysql_fetch_array( $result )) { $last_active = time() - $row['timestamp']; $onlineuser = $row['user']; } if($last_active < 300) { echo $onlineuser; } ?> but all it displays is 1 user... the 1st user i think on the page not them all i have boith user1 and user2 on the page but its only sayin user 1 is on the page?? :S Quote Link to comment Share on other sites More sharing options...
DoddsAntS Posted June 25, 2008 Share Posted June 25, 2008 http://dev.mysql.com/doc/refman/4.1/en/func-op-summary-ref.html Edit to add the rest of the post pre-emptive post click! I would do something like //snip query $activeTime = 300; //max inactivity time $onlineUsers = array(); while($row = mysql_fectch_array($result)) { if((time() - $row['timestamp']) < $activeTime) { $onlineUsers[] = $row['user']; } } if(count($onlineUsers) > 0) { echo join($onlineUsers, " "); } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 humm ok i added the code <?php $result = mysql_query("SELECT * FROM useronline WHERE(file='http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum')"); $activeTime = 300; //max inactivity time $onlineUsers = array(); while($row = mysql_fectch_array($result)) { if((time() - $row['timestamp']) < $activeTime) { $onlineUsers[] = $row['user']; } } if(count($onlineUsers) > 0) { echo join($onlineUsers, " "); } ?> but for somereason it gets ridd of everythin under it and does not display any users Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 ok i tired this <?php include '../settings.php'; $result = mysql_query("SELECT * FROM useronline"); while ($row = mysql_fetch_array($result)) { $last_active = time() - $row['timestamp']; $onlineuser = $row['user']; if ($last_active < 3600) { if(count($onlineuser) > 0) { echo join($onlineuser, " "); } } } ?> b8t i get Warning: join() [function.join]: Invalid arguments passed in /home/runningp/public_html/members/test.php on line 15 Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2008 Share Posted June 25, 2008 Because join expects an array, your passing it a string. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 ahh ok is there any way of joining them in the string then?? Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2008 Share Posted June 25, 2008 <?php include '../settings.php'; if ($result = mysql_query("SELECT * FROM useronline")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $last_active = time() - $row['timestamp']; if ($last_active < 3600) { $onlineuser .= $row['user'] . " "; } } } } echo $onlineuser; ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 ahh yes i see now... ok but how would i make it look like the php version runnerjp, roopurt18, thorpe, jamerson, discomatt, mikenl, SnakeFox, Monk3h, mikelmao, ober, Darkmatter5, Shaba, sarab99, sinista and 105 Guests are viewing this board. but instead of guests its just runnerjp,roopurt18 and thorpe Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2008 Share Posted June 25, 2008 ok but how would i make it look like the php version Um.. it is php. To get the kind of output you want, one way would be to use an array. <?php include '../settings.php'; if ($result = mysql_query("SELECT * FROM useronline")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $last_active = time() - $row['timestamp']; if ($last_active < 3600) { $onlineuser[] = $row['user']; } } } } for ($i=0;$i<count($onlineusers);$i++) { if ($i == count($onlineusers)-1) { echo " and " . $onlineusers[$i]; } else { echo " " . $onlineusers[$i]; } } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 humm how comes if just 1 users is on the page it shows ... and user1 Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2008 Share Posted June 25, 2008 Oh man... do I really need to write the entire thing? <?php include '../settings.php'; if ($result = mysql_query("SELECT * FROM useronline")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $last_active = time() - $row['timestamp']; if ($last_active < 3600) { $onlineuser[] = $row['user']; } } } } if (isset($onlineusers)) { if (count($onlineusers) == 1) { echo $onlineusers[0]; } else { for ($i=0;$i<count($onlineusers);$i++) { if ($i == count($onlineusers)-1) { echo " and " . $onlineusers[$i]; } else { echo " " . $onlineusers[$i]; } } } } ?> 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.