Jump to content

[SOLVED] Table Problems.


seany123

Recommended Posts

soz if this is wrong sections...

 

problem im having is its completely missing out the if($member['staff']{echo ETC...

 

and the ($last_active){ echo ETC goes in its place...

 

<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>World Leaders</strong></td>
  </tr>
</table>
<br>
<table width="54%" border="0" align="left">
<tr>
  <th width="8%"> 
  <th width="26%"><b>Username</b></td>
  <th width="16%"><strong>Position</strong>
  <th width="20%"><strong>Status</strong>
  </tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `staff`, `banned`, `rm`, `ncolor`, `last_active` from `players` order by `staff` desc limit 50");
while($member = $query->fetchrow())
{
    if($member['staff'] >= 1)
{	
    echo "<td>";
    echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";

    if ($member['banned'] >= 1)
    {
    echo "<b>[b] </b>"; 
    echo "<STRIKE>" .$member['username']. "</STRIKE></td>";
    }
    else if ($member['ncolor'] == 1)
    {
    echo "<font color=\"blue\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 2)
    {
    echo "<font color=\"green\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 3)
    {
    echo "<font color=\"yellow\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 4)
    {
    echo "<font color=\"pink\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 5)
    {
    echo "<font color=\"silver\">".$member['username']."</font>";
    }
    else if($member['staff'] >= 1)
    { 
    echo "<font color=\"gold\">".$member['username']."</font>";
    }
    else if($member['rm'] >= 1)
    {
    echo "<font color=\"red\">".$member['username']."</font>";
    }
    else
    {
    echo "<td><font color=\"\">".$member['username']."</font></td>";	
    }

else if($member[`staff`] == 1)
{
echo "<td><font color=\"red\">Forum Moderator</font></td>";
}
else if($member[`staff`] == 2)
{
echo "<td><font color=\"red\">Moderator</font></td>";
}
else if($member[`staff`] == 3)
{
echo "<td><font color=\"red\">Global Moderator</font></td>";	
}
else if($member[`staff`] == 4)
{
echo "<td><font color=\"red\">Admin</font></td>";
}
else if($member[`staff`] == 5)
{
echo "<td><font color=\"red\">Owner</font></td>";	
}

if ($member['last_active'] >= Time()-1200)
    {
    echo "<td><font color=\"lime\">Online</font></td>";
    }
    else
    {
    echo "<td><font color=\"red\">Offline</font></td>";
    }
}
}
?>
</table>

Link to comment
Share on other sites

  
   else if($member[`staff`] == 1)
   {
   echo "<td><font color=\"red\">Forum Moderator</font></td>";
   }
   else if($member[`staff`] == 2)

 

I'm guessing position = staff value.

 

The problem looks like the first if that's checking the staff value is an else if, so it's "else iffing" off of the banned and ncolor checks.

 

Some commenting between those if blocks would make this a bit easier to read and track down.

 

And I don't know what kind of values exist in your database but storing the colors and positions into arrays than simply checking if the value exists in ncolor and staff could knock out a lot of those if statements like this:

 

<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>World Leaders</strong></td>
  </tr>
</table>
<br>
<table width="54%" border="0" align="left">
<tr>
  <th width="8%">
  <th width="26%"><b>Username</b></td>
  <th width="16%"><strong>Position</strong>
  <th width="20%"><strong>Status</strong>
  </tr>
<?php

$colors = array("blue","green","yellow","pink","silver");
$positions = array("Forum Moderator","Moderator","Global Moderator","Admin","Owner");

//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `staff`, `banned`, `rm`, `ncolor`, `last_active` from `players` order by `staff` desc limit 50");
while($member = $query->fetchrow())
{
    if($member['staff'] >= 1)
   {   
    echo "<td>";
    echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";

    if ($member['banned'] >= 1)
    {
    echo "<b>[b] </b>"; 
    echo "<STRIKE>" .$member['username']. "</STRIKE></td>";
    }
    else if ($member['ncolor'] != NULL)
    {
    echo "<font color=\"".$colors[$member['ncolor']]."\">".$member['username']."</font>";
    }
    else if($member['staff'] >= 1)
    { 
    echo "<font color=\"gold\">".$member['username']."</font>";
    }
    else if($member['rm'] >= 1)
    {
    echo "<font color=\"red\">".$member['username']."</font>";
    }
    else
    {
    echo "<td><font color=\"\">".$member['username']."</font></td>";   
    }
   
   if($member[`staff`] != NULL)
   {
   echo "<td><font color=\"red\">".$positions[$member['staff']]."</font></td>";
   }
      
   if ($member['last_active'] >= Time()-1200)
    {
    echo "<td><font color=\"lime\">Online</font></td>";
    }
    else
    {
    echo "<td><font color=\"red\">Offline</font></td>";
    }
}
}
?>
</table>

 

You might have to change a few things based on the values in your database but something like that should work.

Link to comment
Share on other sites

okay so i have changed that to if...

 

i also added a else at the bottom of that set of queries just in case.. but nothing has changed.

 


<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>World Leaders</strong></td>
  </tr>
</table>
<br>
<table width="54%" border="0" align="left">
<tr>
  <th width="8%"> 
  <th width="26%"><b>Username</b></td>
  <th width="16%"><strong>Position</strong>
  <th width="20%"><strong>Status</strong>
  </tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `staff`, `banned`, `rm`, `ncolor`, `last_active` from `players` order by `staff` desc limit 50");
while($member = $query->fetchrow())
{
//This is to stop people being displayed if their staff is lower than 1.	
if($member['staff'] >= 1)
{	
    echo "<td>";
    echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
//This displays the username of each person (in different colors.	
    if ($member['banned'] >= 1)
    {
    echo "<b>[b] </b>"; 
    echo "<STRIKE>" .$member['username']. "</STRIKE></td>";
    }
    else if ($member['ncolor'] == 1)
    {
    echo "<font color=\"blue\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 2)
    {
    echo "<font color=\"green\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 3)
    {
    echo "<font color=\"yellow\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 4)
    {
    echo "<font color=\"pink\">".$member['username']."</font>";
    }
    else if($member['ncolor'] == 5)
    {
    echo "<font color=\"silver\">".$member['username']."</font>";
    }
    else if($member['staff'] >= 1)
    { 
    echo "<font color=\"gold\">".$member['username']."</font>";
    }
    else if($member['rm'] >= 1)
    {
    echo "<font color=\"red\">".$member['username']."</font>";
    }
    else
    {
    echo "<td><font color=\"\">".$member['username']."</font></td>";	
    }

//This shows the Position held by the user.	
if($member[`staff`] == 1)
{
echo "<td><font color=\"red\">Forum Moderator</font></td>";
}
else if($member[`staff`] == 2)
{
echo "<td><font color=\"red\">Moderator</font></td>";
}
else if($member[`staff`] == 3)
{
echo "<td><font color=\"red\">Global Moderator</font></td>";	
}
else if($member[`staff`] == 4)
{
echo "<td><font color=\"red\">Admin</font></td>";
}
else if($member[`staff`] == 5)
{
echo "<td><font color=\"red\">Owner</font></td>";	
}
         else
        {
        echo "<td><font color=\"red\">None</font></td>";
        }

//This shows if the user is on or offline.	
    if ($member['last_active'] >= Time()-1200)
    {
    echo "<td><font color=\"lime\">Online</font></td>";
    }
    else
    {
    echo "<td><font color=\"red\">Offline</font></td>";
    }
}
}
?>
</table>

 

 

 

Link to comment
Share on other sites

added the </td>s

 

and i dont really know where to put the <tr> and </tr>s

 

but ive tried adding them and it still hasnt changed anything...

 


<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>World Leaders</strong></td>
  </tr>
</table>
<br>
<table width="54%" border="0" align="left">
<tr>
  <th width="8%"> 
  <th width="26%"><b>Username</b></td>
  <th width="16%"><strong>Position</strong>
  <th width="20%"><strong>Status</strong>
  </tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `staff`, `banned`, `rm`, `ncolor`, `last_active` from `players` order by `staff` desc limit 50");
while($member = $query->fetchrow())
{
//This is to stop people being displayed if their staff is lower than 1.	
if($member['staff'] >= 1)
{
<tr>	
    echo "<td>";
    echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
//This displays the username of each person (in different colors.

    if ($member['banned'] >= 1)
    {
    echo "<td><b>[b] </b></td>"; 
    echo "td><STRIKE>" .$member['username']. "</STRIKE></td>";
    }
    else if ($member['ncolor'] == 1)
    {
    echo "</td><font color=\"blue\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 2)
    {
    echo "</td><font color=\"green\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 3)
    {
    echo "<td><font color=\"yellow\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 4)
    {
    echo "<td><font color=\"pink\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 5)
    {
    echo "<td><font color=\"silver\">".$member['username']."</font></td>";
    }
    else if($member['staff'] >= 1)
    { 
    echo "<td><font color=\"gold\">".$member['username']."</font></td>";
    }
    else if($member['rm'] >= 1)
    {
    echo "<td><font color=\"red\">".$member['username']."</font></td>";
    }
    else
    {
    echo "<td><font color=\"\">".$member['username']."</font></td>";	
    }
</tr>

//This shows the Position held by the user.	
if($member[`staff`] == 1)
{
<tr>
echo "<td><font color=\"red\">Forum Moderator</font></td>";
}
else if($member[`staff`] == 2)
{
echo "<td><font color=\"red\">Moderator</font></td>";
}
else if($member[`staff`] == 3)
{
echo "<td><font color=\"red\">Global Moderator</font></td>";	
}
else if($member[`staff`] == 4)
{
echo "<td><font color=\"red\">Admin</font></td>";
}
else if($member[`staff`] == 5)
{
echo "<td><font color=\"red\">Owner</font></td>";	
}
        else
        {
        echo "<td><font color=\"red\">None</font></td>";
        }
</tr>

//This shows if the user is on or offline.	
if ($member['last_active'] >= Time()-1200)
<tr>
    {
    echo "<td><font color=\"lime\">Online</font></td>";
    }
    else
    {
    echo "<td><font color=\"red\">Offline</font></td>";
    }
</tr>
}
}
?>
</table>

 

just realised the <tr> tags need to be in the echos lol

Link to comment
Share on other sites

Looked through your code and saw what seemed to be problems in your html. This may not fix it, but try it and see what happens. Here's the entire adjusted code:

 


<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>World Leaders</strong></td>
  </tr>
</table>
<br>
<table width="54%" border="0" align="left">
<tr>
  <th width="8%" />
  <th width="26%"><b>Username</b></th>
  <th width="16%"><strong>Position</strong></th>
  <th width="20%"><strong>Status</strong></th>
  </tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `staff`, `banned`, `rm`, `ncolor`, `last_active` from `players` order by `staff` desc limit 50");
while($member = $query->fetchrow())
{
//This is to stop people being displayed if their staff is lower than 1.   
if($member['staff'] >= 1)
{   
    echo "<tr>";
echo "<td />";
    echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
//This displays the username of each person (in different colors.   
    if ($member['banned'] >= 1)
    {
    echo "<b>[b] </b>"; 
    echo "<STRIKE>" .$member['username']. "</STRIKE></td>";
    }
    else if ($member['ncolor'] == 1)
    {
    echo "<font color=\"blue\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 2)
    {
    echo "<font color=\"green\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 3)
    {
    echo "<font color=\"yellow\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 4)
    {
    echo "<font color=\"pink\">".$member['username']."</font></td>";
    }
    else if($member['ncolor'] == 5)
    {
    echo "<font color=\"silver\">".$member['username']."</font></td>";
    }
    else if($member['staff'] >= 1)
    { 
    echo "<font color=\"gold\">".$member['username']."</font></td>";
    }
    else if($member['rm'] >= 1)
    {
    echo "<font color=\"red\">".$member['username']."</font></td>";
    }
    else
    {
    echo "<td><font color=\"\">".$member['username']."</font></td>";   
    }

//This shows the Position held by the user.   
   if($member[`staff`] == 1)
   {
   echo "<td><font color=\"red\">Forum Moderator</font></td>";
   }
   else if($member[`staff`] == 2)
   {
   echo "<td><font color=\"red\">Moderator</font></td>";
   }
   else if($member[`staff`] == 3)
   {
   echo "<td><font color=\"red\">Global Moderator</font></td>";   
   }
   else if($member[`staff`] == 4)
   {
   echo "<td><font color=\"red\">Admin</font></td>";
   }
   else if($member[`staff`] == 5)
   {
   echo "<td><font color=\"red\">Owner</font></td>";   
   }
   else
   {
   echo "<td><font color=\"red\">None</font></td>";
   }

   //This shows if the user is on or offline.   
    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>";
}
}
?>
</table>

 

You were missing a lot of closing tags. The new table row tags are in there as well.

Link to comment
Share on other sites

okay the problem is with the ==.

 

it displays what it correctly if i just used 1 =

 

if($member[`staff`] == 1)
    {
    echo "<td><font color=\"\">Forum Moderator</font>";
    }
    else if($member[`staff`] == 2)
    {
    echo "<td><font color=\"\">Moderator</font>";
    }
    else if($member[`staff`] == 3)
    {
    echo "<td><font color=\"\">Global Moderator</font>";
    }
    else if($member[`staff`] == 4)
    {
    echo "<td><font color=\"\">Admin</font></td>";
    }
    else if($member[`staff`] == 5)
    {
    echo "<td><font color=\"\">Owner</font>";
    }

 

but obviously if i just used 1 = then it would say "Forum moderator" for everyone even people who have higher ['staff']...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.