Lamez Posted December 18, 2007 Share Posted December 18, 2007 I want to filter out all the online people, I have been messing around with this: <?php /* Display table contents */ $query = mysql_query("SELECT u.username FROM users u INNER JOIN active_users a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username='$uname'")or die(mysql_error()); if (mysql_num_rows($query) > 0){ //somthing to filter out online peeps } else { echo "<table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; //Table's Specs echo "<tr>\n"; echo "<td valign=\"bottom\"><strong>Username</strong></td>\n"; //Username Column echo "<td width=\"80\" valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Email</strong></td>\n"; //Email Column echo "<td valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Status</strong></td>\n"; //Status Column echo "</tr>\n"; echo "<tr>\n"; echo "<td height=\"1\" colspan=\"5\" align=\"center\" valign=\"top\"><div class=\"dot\"></div></td>\n"; //Dotted Line echo "</tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $email = /*mysql_result($result,$i,"email");*/ "$uname"; $time = mysql_result($result,$i,"timestamp"); echo "<tr>\n"; echo "<td><a href=\"userinfo.php?user=$uname\">$uname</a><br></td>\n"; echo "<td> </td>\n"; echo "<td>$email</td>\n"; echo "<td> </td>\n"; echo "<td align=\"left\">\n"; /* Tells the if they are online or offline */ $query = mysql_query("SELECT u.username FROM users u INNER JOIN active_users a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username='$uname'")or die(mysql_error()); if (mysql_num_rows($query) > 0){ echo "<font color=\"#04db04\">Online</font>"; } else { echo "<font color=\"#FF0000\">Offline</font>"; } } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } } ?> I am not sure on how to filter them out. Any help? also if I wanted to pull username, and timestamp from one table and add email for users from another table, would this be right? MySql query: $q = "SELECT username, timestamp " ."FROM".TBL_ACTIVE_USERS. "INNER JOIN".TBL_USERS."ON" .TBL_ACTIVE_USERS.username = .TBL_USERS.email "ORDER BY" timestamp DESC,username Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/ Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 The query looks like it only selects people that are online (or active within the last 5 minutes) so you probably need a different query. Try changing the lessthan sign to greater than at the "a.timestamp < (Now() - INTERVAL 5 MINUTE)" part and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417825 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 nothing it shows all members, offline and online. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417828 Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 Is there something in the database that specifies if a user is online or off? What do you use to discern between online and offline users? Maybe post all the fields for your database. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417832 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 I have a active_users table, that tells all the online users. and just a regular table called users, that has the name, id, password, email, about, age, and so on.. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417841 Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 Does active_users not have a username column? If it does, there is no reason to JOIN the two tables since that is the only field you are retrieving. Otherwise, I think you can do it without join. Something like: "SELECT u.username FROM users u, active_users a WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND a.username='$uname' AND u.username=a.username"; I think that should only select the username from users that match the criteria presented to active_users. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417844 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 it worked, but now it is not showing my table, ever thing is smooshed together. http://www.lamezz.com/user/viewmembers.php?sort=offline did I put my query in the wrong spot? /*Sorts by Offline*/ function displayOffline(){ global $database; $q = "SELECT username,email,timestamp " ."FROM ".TBL_USERS." ORDER BY timestamp DESC,username"; $result = $database->query($q); /*Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; //Table's Specs echo "<tr>\n"; echo "<td valign=\"bottom\"><strong>Username</strong></td>\n"; //Username Column echo "<td width=\"80\" valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Email</strong></td>\n"; //Email Column echo "<td valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Status</strong></td>\n"; //Status Column echo "</tr>\n"; echo "<tr>\n"; echo "<td height=\"1\" colspan=\"5\" align=\"center\" valign=\"top\"><div class=\"dot\"></div></td>\n"; //Dotted Line echo "</tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $query = mysql_query("SELECT u.username FROM users u, active_users a WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND a.username='$uname' AND u.username=a.username")or die(mysql_error()); if (mysql_num_rows($query) > 0){ //somthing to filter out online peeps } else { //show offline peeps echo "<tr>\n"; echo "<td><a href=\"userinfo.php?user=$uname\">$uname</a><br></td>\n"; echo "<td> </td>\n"; echo "<td>$email</td>\n"; echo "<td> </td>\n"; echo "<td align=\"left\">\n"; /*displayStatus();*/ echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } } } also is it possible to call a function inside of a function? Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417857 Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 I have to be logged in to view that page, so I'm not sure what you are talking about. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417929 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 oh sorry login with: user: test1 pass: test then have a look, it looks all messy Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417933 Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 You are ending the table tag after every user. I don't even see it in your newest post, but in your first post, at the very bottom, the </table> tag is inside your while loop. It shouldn't be. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417937 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 I don't understand. here is my latest code /*Sorts by Offline*/ function displayOffline(){ global $database; $q = "SELECT username,email,timestamp " ."FROM ".TBL_USERS." ORDER BY timestamp DESC,username"; $result = $database->query($q); /*Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; //Table's Specs echo "<tr>\n"; echo "<td valign=\"bottom\"><strong>Username</strong></td>\n"; //Username Column echo "<td width=\"80\" valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Email</strong></td>\n"; //Email Column echo "<td valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Status</strong></td>\n"; //Status Column echo "</tr>\n"; echo "<tr>\n"; echo "<td height=\"1\" colspan=\"5\" align=\"center\" valign=\"top\"><div class=\"dot\"></div></td>\n"; //Dotted Line echo "</tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $query = mysql_query("SELECT u.username FROM users u, active_users a WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND a.username='$uname' AND u.username=a.username")or die(mysql_error()); if (mysql_num_rows($query) > 0){ //somthing to filter out online peeps } else { //show offline peeps and hide online echo "<tr>\n"; echo "<td><a href=\"userinfo.php?user=$uname\">$uname</a><br></td>\n"; echo "<td> </td>\n"; echo "<td>$email</td>\n"; echo "<td> </td>\n"; echo "<td align=\"left\">\n"; $online = mysql_query("SELECT u.username FROM users u INNER JOIN active_users a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username='$uname'")or die(mysql_error()); if (mysql_num_rows($online) > 0){ echo "<font color=\"#04db04\">Online</font>"; } else { echo "<font color=\"#FF0000\">Offline</font>"; } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } } } I have the ending table tags Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417940 Share on other sites More sharing options...
lemmin Posted December 18, 2007 Share Posted December 18, 2007 Yeah, at the very bottom, change: //... } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } } } to: } echo "</td>\n"; echo "</tr>\n"; } } echo "</table>\n"; } I think that is where you want it, just take it out of your for loop (I said while loop, but I meant for.). Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417943 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 thank you very much!! that did it! Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417944 Share on other sites More sharing options...
trq Posted December 18, 2007 Share Posted December 18, 2007 Sorry, but your code is incredibly hard to read if simply for the fact that there is no consistant endentation. One thing I did notice is this.... $num_rows = mysql_numrows($result); outght be.... $num_rows = mysql_num_rows($result); I also don't understand why you have so many queries within the one function, but then again, like I said, your code is pretty hard to read / follow. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417946 Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 sorry I am a noob, and I hate to indent when I am coding. I know I should. Quote Link to comment https://forums.phpfreaks.com/topic/82220-solved-if-statment-help/#findComment-417952 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.