zearthur Posted January 29, 2013 Share Posted January 29, 2013 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" Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/ Share on other sites More sharing options...
Jessica Posted January 29, 2013 Share Posted January 29, 2013 Have just one if() before you echo the row. Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409032 Share on other sites More sharing options...
loren646 Posted January 29, 2013 Share Posted January 29, 2013 why do you have <?php on every line? why not just echo? Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409033 Share on other sites More sharing options...
zearthur Posted January 29, 2013 Author Share Posted January 29, 2013 (edited) Have just one if() before you echo the row. You might translate to someone who does not understand it at all? why do you have <?php on every line? why not just echo? I don't know. I got this code here: http://dev.bukkit.org/server-mods/online-players-sql/pages/example-php-file/ Edited January 29, 2013 by zearthur Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409034 Share on other sites More sharing options...
Jessica Posted January 29, 2013 Share Posted January 29, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409035 Share on other sites More sharing options...
zearthur Posted January 29, 2013 Author Share Posted January 29, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409039 Share on other sites More sharing options...
Jessica Posted January 29, 2013 Share Posted January 29, 2013 (edited) 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 January 29, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409041 Share on other sites More sharing options...
cyberRobot Posted January 30, 2013 Share Posted January 30, 2013 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>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/273802-mysql-list-help/#findComment-1409137 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.