Jump to content

php / mysql question..


seany123

Recommended Posts

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.