Jump to content

Mysql list help


zearthur

Recommended Posts

Hey guys, I'm so bad in php... Can someone do this to me please?

 

I have this code:

<?php
 $mysql = new mysqli("--", "--", "--", "--");


 $sqlOnlineList = "SELECT * FROM online_players";
 $result = $mysql->query($sqlOnlineList);
?>


<html>
 <head>
   <title>The Lost Server</title>
 </head>


<body>
   <h3>Vendetta's Minecraft Server: Online Players</h3>
<table width="100%">
     <thead>
       <tr>
         <td width="15%">Player</td>
         <td width="15%">Group</td>
         <td width="15%">World</td>
         <td width="55%">Logged On</td>
       </tr>
     </thead>
     <tfoot><tr><td colspan="4"></td></tr></tfoot>
     <tbody>
 <?php while($OnlineName = $result->fetch_object()): ?>
  <tr>
             <td><?php if ( $OnlineName->online == "1" ) echo $OnlineName->player; ?></td>
             <td><?php if ( $OnlineName->online == "1" ) echo $OnlineName->permission_group; ?></td>
             <td><?php if ( $OnlineName->online == "1" ) echo $OnlineName->current_world; ?></td>
             <td><?php if ( $OnlineName->online == "1" ) echo date("F j, Y, g:i a", $OnlineName->logon_time); ?></td>
           </tr>
       <?php endwhile; ?>
     </tbody>
   </table>
   <p>  <?php while($OnlineName = $result->fetch_object()): ?> 
      <img src="https|//minotar.net/avatar/.png">
<?php endwhile; ?></p>
</body>
</html>

 

But this shows blank tables(Probably $OnlineName->online == "0" )... I need to hide completely this tables and show only the $OnlineName->online == "1"

Link to comment
Share on other sites

If you don't understand, it's time to learn. What about that did you not understand? It's fairly basic. You have four lines with if statements. Get rid of them and just have one before you ever echo the <tr>. Put all of the table row within your if construct.

Link to comment
Share on other sites

If you don't understand, it's time to learn. What about that did you not understand? It's fairly basic. You have four lines with if statements. Get rid of them and just have one before you ever echo the <tr>. Put all of the table row within your if construct.

Did you mean this?

 

<?php
 $mysql = new mysqli("---", "---", "---", "---");


 $sqlOnlineList = "SELECT * FROM online_players";
 $result = $mysql->query($sqlOnlineList);
?>


<html>
 <head>
   <title>The Lost Server</title>
 </head>


<body>
<h3>Vendetta's Minecraft Server: Online Players</h3>
<table width="100%" border="1" cellpadding="1" cellspacing="1">
     <thead>
       <tr>
         <td width="15%">Player</td>
       </tr>
     </thead>
     <tfoot><tr><td></td></tr></tfoot>
     <tbody>
 <?php while($OnlineName = $result->fetch_object()): ?>
  <tr>
             <td><?php if ( $OnlineName->online == "1" ) echo $OnlineName->player; ?>
           </tr>
       <?php endwhile; ?>
     </tbody>
   </table>
</body>
</html>

If yes, this don't solve the problem. Check this: http://177.17.68.57:8090/Site-Mineninja/players.php. I'll leave online for a while.

Link to comment
Share on other sites

do you know HTML at all?

Your if statement is still within the <tr> not outside of it, and you erased all of your td stuff.

 

Edit: Do you want to learn PHP and HTML or do you just need this one part changed? If the latter, try our freelance forum.

Edited by Jessica
Link to comment
Share on other sites

As Jessica mentioned, you'll need to wrap the entire table row with the if statement instead of the individual column values. You could, for example, do something like this:

 

<?php
while($OnlineName = $result->fetch_object()) {
    if($OnlineName->online == "1") {
         echo '<tr>';
         echo "<td>$OnlineName->player</td>";
         echo "<td>$OnlineName->permission_group</td>";
         echo "<td>$OnlineName->current_world</td>";
         echo '<td>' . date("F j, Y, g:i a", $OnlineName->logon_time) . '</td>';
         echo '</tr>';
    }
}
?>

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.