erobins Posted October 10, 2008 Share Posted October 10, 2008 I am very new to PHP Coding, and have been going nutz trying to format and display this data base query table. The have actually got the following code to work...It just does not do what I want it to! LOL Here is the code : _______________________________________________________________________ opentable('Players now Online'); $result = dbquery ( "SELECT * FROM `characters` WHERE `online` = '1' ORDER BY `level` DESC" ); $rows = dbrows($result); $rowstart = 0; if ($rows != 0) { $i = 0; echo "<table align='center' cellpadding='0' cellspacing='1' width='250' class='tbl-border'> <tr> <td align='center' width='1%' class='tbl2' style='white-space:nowrap'><b>Player Name</b></td> <td align='center' width='1%' class='tbl2' style='white-space:nowrap'><b>Level</b></td> <td align='center' width='1%' class='tbl2' style='white-space:nowrap'><b></b></td> <td align='center' width='1%' class='tbl2' style='white-space:nowrap'><b>Player Name</b></td> <td align='center' width='1%' class='tbl2' style='white-space:nowrap'><b>Level</b></td> </tr>\n"; while ($data = dbarray($result)) { $cell_color = ($i % 2 == 0 ? "tbl1" : "tbl2"); echo "<tr><td class='$cell_color' style='white-space:nowrap'>".$data[name]."</td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'>".$data[level]."</td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'></td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'>".$data[name]."</td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'>".$data[level]."</td>"; } } ELSE { echo "<center><br>\n There are no players currently online.</center><br>\n"; } echo "</table>\n"; closetable(); _______________________________________________________________________ Here is what the code displays : (Notice how the same names are repeated) Player Name Level Player Name Level Player A 5 Player A 5 Player B 5 Player B 5 Player C 5 Player C 5 Here is what I want it to look like : (Three collumn table) Player Name Level Player Name Level Player Name Level Player A 5 Player B 5 Player C 5 Player A 5 Player B 5 Player C 5 Player A 5 Player B 5 Player C 5 I know this will require midifying the While loop, and also the Table display, but everything I try just crashes and burns! Anyone can help me with this code please? Thanks! Ed Quote Link to comment https://forums.phpfreaks.com/topic/127913-solved-data-base-query-table/ Share on other sites More sharing options...
fanfavorite Posted October 10, 2008 Share Posted October 10, 2008 Try something like: $count = 1; while ($data = dbarray($result)) { if ($count > 1) { echo "<td align='center' width='1%' class='$cell_color' style='white-space:nowrap'></td>"; } $cell_color = ($i % 2 == 0 ? "tbl1" : "tbl2"); echo "<tr><td class='$cell_color' style='white-space:nowrap'>".$data[name]."</td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'>".$data[level]."</td>"; if ($count == 3) { $count = 1; } else { $count++; } } Quote Link to comment https://forums.phpfreaks.com/topic/127913-solved-data-base-query-table/#findComment-662279 Share on other sites More sharing options...
erobins Posted October 11, 2008 Author Share Posted October 11, 2008 I added that to my code, and it comes close. It only displays 1 name and level, and then drops down to the next line. (Should be 3 names and levels per line) But with a slight modification I got it to work. THANKS FOR THE HELP!!!! REALLY! MODIFIED CODE __________________________________________________________ $count = 1; while ($data = dbarray($result)) { if ($count > 1) { echo "<td align='center' width='1%' class='$cell_color' style='white-space:nowrap'></td>"; } $cell_color = ($i % 2 == 0 ? "tbl1" : "tbl2"); echo "<td class='$cell_color' style='white-space:nowrap'>".$data[name]."</td> <td align='center' width='1%' class='$cell_color' style='white-space:nowrap'>".$data[level]."</td>"; if ($count == 3) { $count = 1; echo "<tr>"; } else { $count++; } } __________________________________________________________ Quote Link to comment https://forums.phpfreaks.com/topic/127913-solved-data-base-query-table/#findComment-662426 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.