tmfl Posted April 29, 2011 Share Posted April 29, 2011 Hi, The code for displaying a results set in multiple columns (http://www.phpfreaks.com/forums/index.php?topic=95426.0) works really well and displays 1 2 3 4 5 6 7 8 Does anyone know how to change so it displays as 1 3 5 7 2 4 6 8 Any help would be greatly appreciated thanks a Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/ Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 so you want to order the id's by the odds first..then the evens? Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208187 Share on other sites More sharing options...
tmfl Posted April 29, 2011 Author Share Posted April 29, 2011 Thanks for the reply fugix, I've got a membership list which I am returning I want my table to have 4 columns and, say, 20 rows at the moment... Member 1 Member 3 Member 2 Member 4 .. Member 20 Member 40 I'm not sure how to open the row, populate the 1st table cell then close the row open the 2nd row etc then when I get to the 21st member I will have to re-open the first row and populate the 2nd cell.... I'm not sure also by what you mean when u say order by odd/even ids thanks a Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208194 Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 if so...you can change $query = "SELECT product FROM selling_items ORDER BY prod_id"; to $query = "SELECT product FROM selling_items WHERE MOD(<row>,2) = 1 ORDER BY prod_id"; for odds and $query = "SELECT product FROM selling_items WHERE MOD(<row>,2) = 0 ORDER BY prod_id"; for evens Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208195 Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 looks like i posted at the same time you did...I may have misinterpreted what you are looking for..I will look at what you have Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208198 Share on other sites More sharing options...
tmfl Posted April 29, 2011 Author Share Posted April 29, 2011 thanks for your help fugix but I got another piece of code from the forums here http://www.phpfreaks.com/forums/index.php?topic=211937.msg965544#msg965544 it works a treat... thanks again Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208256 Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 no problem Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208258 Share on other sites More sharing options...
tmfl Posted April 29, 2011 Author Share Posted April 29, 2011 Just did some further testing with this and it doesnt render the table correctly on IE8 or Chrome 10....works fine in Firefox tho!....back to the drawing board.... anyone ? ta..... a Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208378 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 Post your actual code here. Your cannot expect the the codes you're trying will work straight away for you. They will need to be adapted to work with your data. Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208382 Share on other sites More sharing options...
tmfl Posted April 29, 2011 Author Share Posted April 29, 2011 ok... the code is as follows... $num_results = mysql_num_rows($res); $num_cols = 4; $num_rows_decimal = $num_results / $num_cols; $num_rows = ceil($num_rows_decimal); $rows = array(); $j = 1; while($row = mysql_fetch_assoc($res)) { $data = $row['firstname'].' '.$row['lastname']; @$rows[$j] .= ' <td class="member">'.$data."</td>"; if($j == $num_rows) $j = 0; $j++; } echo '<table class="losfinal"> <thead> <tr> <th colspan="4">Players</th> </tr> </thead>'; foreach($rows as $row) { echo " <tr>" . $row . " </tr>"; } echo '</table>'; The live page where its running is http://www.horeswoodgaa.com/membership.php and as i said it works fine in Firefox but not in IE8 or Chrome 10 (all on Windows) Go to the 2011 Membership table and cells and border is missing. thanks for your help. a Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208389 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 Okay, I see the problem. My original code which you're basing your code off of is not smart enough to output the desired amount of <td></td> to complete the table structure. That is why your table borders are not matching up. I'll see if I can fix my original code. Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208398 Share on other sites More sharing options...
tmfl Posted April 29, 2011 Author Share Posted April 29, 2011 ah ok.....well thanks v much for looking at it........i've been looking around for a while today on code that prints the result set top down and then left to right.....yours was by far the best i've seen.... just another quick question for you...i've never seen the @ symbol used like this before..... @$rows[$j] .= ' <td class="member">'.$data."</td>"; i'm googling now to see what it means......maybe you could explain too.... thanks again for all your help.... a Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208402 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 Okay I have fixed the code. Change this line @$rows[$j] .= ' <td class="member">'.$data."</td>"; to @$rows[$j][] = ' <td class="member">'.$data."</td>"; Now change the foreach loop to foreach($rows as $row) { echo " <tr>" . implode("\n", $row); // if the current row doesn't have enough columns // then output the required number of blank cells to complete the row if($j = (count($row) < $num_cols)) { for($i = 0; $i < $j; $i++) echo '<td class="member"></td>'; } echo " </tr>"; } The @ symbol is used for error suppression. Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208416 Share on other sites More sharing options...
tmfl Posted April 30, 2011 Author Share Posted April 30, 2011 thanks wildteen88.....works perfectly..... Quote Link to comment https://forums.phpfreaks.com/topic/235088-multi-column-results-code-snippet-repository/#findComment-1208620 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.