seany123 Posted March 30, 2009 Share Posted March 30, 2009 basically i have a table called "players" in my database.. it hold all the information about all the people registered on my site... now when i wanna call a value off the database for myself i use.... if ($player->last_active >= Time()-1200) { echo "<td><span class=\"onlinegreen\">Online</span></td>"; } else { but im trying to make a page which shows all the people and i want it to show everyones online status.... using the code above... everybody is online because im online... understand? all help would be great. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/ Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 Is it that $player->last_active used your info (as in the person executing the script)? Modify it to accept a perimeter to specify the user to look up. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797323 Share on other sites More sharing options...
seany123 Posted March 30, 2009 Author Share Posted March 30, 2009 yeah because $player->last_active... checks my values... it showed everyone else online also..... i have a list of people... the list is random so it could be anyone... i want it to show if they are online or offline. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797329 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 Sorry, I'm not to huge on classes and objects (I'm that kind of a programmer that doesn't use if I don't need it, learn it when I do). Some how you need to get that function or a new function to lookup the user's info based on a parameter like their unique id. I'd just write a query inside your loop to pull their last_active info. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797340 Share on other sites More sharing options...
seany123 Posted March 30, 2009 Author Share Posted March 30, 2009 i tried this... $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $lastactive = $row['last_active']; } ?> but it didnt work. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797374 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 anybody else able to help me with this. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797797 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 if you use the code tags around your php or even html snipits, you will likely get more help [ code ]Like this but without the spaces in the tags[ /code ] would be Like this but without the spaces in the tags In what way did it not work? Did it give you an error or did you simply not get the results you expected? Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797804 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 well all the people had their online status to offline.. (in white).. so it obviously didnt understand what $lastactive was equal to. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797811 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 were you doing it inside the loop or is the code you posted literally what you have? Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797815 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 to be honest ive been trying not to post the Whole code because then it might make everything more confusing... i just wanted to have a list of the players and it to show if they are online or not... anyway here is the whole code: <?php include("lib.php"); define("PAGENAME", "Hall Of Fame"); $player = check_user($secret_key, $db); $i = 1; include("templates/private_header.php"); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $lastactive = $row['last_active']; } ?> <style type="text/css"> <!-- body, td, th { color: #FFFFFF; } body { background-color: #000000; } a:link { color: #FF0000; } a:visited { color: #FF0000; } a:hover { color: #666666; } a:active { color: #FF0000; } .style5 {color: #FFFFFF} --> </style> <table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"> <tr> <td align="center" class="style5"><strong>Hall Of Fame </strong></td> </tr> </table> <table width="660" border="0"> <tr> <td width="90"><div align="center"><a href="levelhof.php">Level</a></div></td> <td width="90"><div align="center"><a href="moneyhof.php">Money</a></div></td> <td width="90"><div align="center"><a href="bankhof.php">Bank</a></div></td> <td width="90"><div align="center"><a href="pointshof.php">Points</a></div></td> <td width="90"><div align="center"><a href="strengthhof.php">Strength</a></div></td> <td width="90"><div align="center"><a href="defencehof.php">Defence</a></div></td> <td width="90"><div align="center"><a href="speedhof.php">Speed</a></div></td> </tr> </table> <br> <table width="54%" border="0" align="left"> <tr> <th width="8%"> <th width="14%">Rank <th width="26%"><b>Username</b> </td> <th width="16%"><strong>Level</strong> <th width="20%"><strong>Money</strong> <th width="16%">Status</tr> <?php //Select all members ordered by level (highest first, members table also doubles as rankings table) $query = $db->execute("select `id`, `username`, `level`, `money` from `players` order by `level` desc limit 50"); while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; echo $member['username']; echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($row['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } ?> </table> <div align="center"> </div> Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797819 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 go ahead and get rid of this $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $lastactive = $row['last_active']; } change the other query to: "select `id`, `username`, `level`, `money`, `last_active` from `players` order by `level` desc limit 50" (Added last_active to field list) See if that works Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797824 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 good thinking... ill check. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797836 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 Just getting a blank white page now... <?php include("lib.php"); define("PAGENAME", "Hall Of Fame"); $player = check_user($secret_key, $db); $i = 1; include("templates/private_header.php"); ?> <style type="text/css"> <!-- body, td, th { color: #FFFFFF; } body { background-color: #000000; } a:link { color: #FF0000; } a:visited { color: #FF0000; } a:hover { color: #666666; } a:active { color: #FF0000; } .style5 {color: #FFFFFF} --> </style> <table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"> <tr> <td align="center" class="style5"><strong>Hall Of Fame </strong></td> </tr> </table> <table width="660" border="0"> <tr> <td width="90"><div align="center"><a href="levelhof.php">Level</a></div></td> <td width="90"><div align="center"><a href="moneyhof.php">Money</a></div></td> <td width="90"><div align="center"><a href="bankhof.php">Bank</a></div></td> <td width="90"><div align="center"><a href="pointshof.php">Points</a></div></td> <td width="90"><div align="center"><a href="strengthhof.php">Strength</a></div></td> <td width="90"><div align="center"><a href="defencehof.php">Defence</a></div></td> <td width="90"><div align="center"><a href="speedhof.php">Speed</a></div></td> </tr> </table> <br> <table width="54%" border="0" align="left"> <tr> <th width="8%"> <th width="14%">Rank <th width="26%"><b>Username</b> </td> <th width="16%"><strong>Level</strong> <th width="20%"><strong>Money</strong> <th width="16%">Status</tr> <?php //Select all members ordered by level (highest first, members table also doubles as rankings table) "select `id`, `username`, `level`, `money` from `players` order by `level` desc limit 50" while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; echo $member['username']; echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($member['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } ?> </table> <div align="center"> </div> Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797845 Share on other sites More sharing options...
lonewolf217 Posted March 31, 2009 Share Posted March 31, 2009 blank page typically means an error. turn on error reporting in php.ini and see what you get Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797854 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 i dunno how to do that... im looking through peoples sigs on here to find that code.... Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797857 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 top of the page add error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797862 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 line 60, its fubar I think you intended $query = $db->execute("select `id`, `username`, `level`, `money` from `players` order by `level` desc limit 50"); but you are still missing the last_active field in your list.... you need: $query = $db->execute("select `id`, `username`, `level`, `money`, `last_active` from `players` order by `level` desc limit 50"); Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797868 Share on other sites More sharing options...
seany123 Posted March 31, 2009 Author Share Posted March 31, 2009 we have lift off!!! yes it seems to have worked now, just moved some code around and its all good. thankyou all for the great and promt help. Link to comment https://forums.phpfreaks.com/topic/151841-php-mysql-question/#findComment-797873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.