joebudden Posted May 6, 2007 Share Posted May 6, 2007 hi guys, Iv got a table that displays each record from a query. The problem is theres a lot of records and I just wondered if there was a way of creating a 3 tables side by side to make the information displayed more compact but not using separate queries ?? here is the code so far <?php // get players A - J $getPlayersSQL = "SELECT playerId,playerName,playerSurname FROM player ORDER BY playerSurname ASC"; $getPlayersRES = mysql_query($getPlayersSQL); ?> <form action="createMyTeamConfirm.php" method="post"> <input type="submit" name="submit" value="Continue"><br /><br /> <input type="hidden" name="teamId" value="<?php echo $teamId ?>" /> <input type="hidden" name="leagueId" value="<?php echo $teamId ?>" /> <table width="200px" border="1" align="center" cellpadding="0" cellspacing="0"> <tr><td></td><td>Player Name</td></tr> <?php while($players = mysql_fetch_assoc($getPlayersRES)) { // hold the players details in variables $playerId = $players["playerId"]; $playerName = $players["playerName"]; $playerSurname = $players["playerSurname"]; // create the table rows echo "<tr>"; echo "<td align=\"center\"><input type=\"checkbox\" name=\"add_players[]\" value=\"$playerId\" /></td>"; echo "<td align=\"center\">"; ?> <a href="javascript:openWindow('playerInformation.php?playerId=<?php echo $playerId;?>', 500, 400, 200, 200)"> <?php echo $playerName."<b> "; echo $playerSurname."</b>"; ?> </a> <?php echo "</td>"; echo "</tr>"; } ?> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/ Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 what are the 3 queries ? you could try to build them into one but without knowing the schema its impossible hard to say Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-246745 Share on other sites More sharing options...
clown[NOR] Posted May 6, 2007 Share Posted May 6, 2007 what you can is to use a if statement... then count how many times while has started over... every 3rd time you add </tr><tr> something like this if ($count == 3) { echo "</tr><tr>"; $i = 1; <?php // Do all query stuff $i=1; while ($players = mysql_fetch_assoc($getPlayersRES)) { if ($i == 3) { echo "</tr><tr>"; $i=1; } // Do all the things you want to do here... $i++ } ?> PS: I haven't tested it, but it should work Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-246747 Share on other sites More sharing options...
skali Posted May 6, 2007 Share Posted May 6, 2007 You can fetch all the records from the queries in an array while($row=mysql_fetch_array($getPlayersRES)){//fetch all records in the array $records[count($records)] = $row; } now you can use this array anyway you like. Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-246748 Share on other sites More sharing options...
joebudden Posted May 6, 2007 Author Share Posted May 6, 2007 cheers for the help guys but i dont think these solutions help me. what i have, is lets say 100 names, in a table and it scrolls a long way down the page. Just wondered if there was a way of having 10 names then stop and create a new table next to that and so on. Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-246778 Share on other sites More sharing options...
clown[NOR] Posted May 7, 2007 Share Posted May 7, 2007 are you talking about making a new table or make it so the person can click "next" to see the next ten names and so on? if so you want to know about pagination or w/e it's called Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-247031 Share on other sites More sharing options...
genericnumber1 Posted May 7, 2007 Share Posted May 7, 2007 http://www.phpfreaks.com/tutorials/43/0.php Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-247032 Share on other sites More sharing options...
suttercain Posted May 7, 2007 Share Posted May 7, 2007 I think you are saying.... 1 | 11 | 21 2 | 12 | 22 3 | 13 | 23 etc... Am I right? Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-247040 Share on other sites More sharing options...
Barand Posted May 7, 2007 Share Posted May 7, 2007 Store the data in an array then use this method <?php $ar = range(1,12); $k = count ($ar); $cols = 4; $rows = ceil($k/$cols); echo '<table border="1">'; for ($r=0; $r < $rows; $r++) { echo '<tr>'; for ($c=0; $c < $cols; $c++) { echo "<td>{$ar[$r+$rows*$c]}</td>"; } echo '</tr>'; } echo '</table>'; ?> gives->[pre] 1 4 7 10 2 5 8 11 3 6 9 12 [/pre] If the data doesn't have to be in individual table cells, then something like this <?php include '../test/db.php'; $sql = "SELECT player_name, player_surname FROM player ORDER BY player_surname"; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $cols = 3; $rows = ceil(mysql_num_rows($res)/$cols); $k = 0; echo '<table border="1"><tr>'; while (list($n, $s) = mysql_fetch_row($res)) { if ($k % $rows == 0) echo '<td>'; echo "<b>$s</b><br>$n<br><br>"; $k++; if ($k % $rows == 0) echo '</td>'; } echo '</tr></table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50270-quick-question/#findComment-247096 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.