Switch0r Posted March 22, 2006 Share Posted March 22, 2006 Hey peeps, wonder if anyone can help me. I'm prob just being numb, but i could do with the help :)I'm trying to split a set of records from a db into a 2 column table, rather than one long list.eg12345-->1 | 42 | 53 |If you see what i mean....would i be best in creating 2 queries and echoing the results separately or is there an easier way?and if the above is the case, how do i only echo a range of results?thanks to anyone who can help me :) Quote Link to comment Share on other sites More sharing options...
craygo Posted March 22, 2006 Share Posted March 22, 2006 Do you want seperate columns on one page, or divide up the results on seperate pages with one column on each page?? Quote Link to comment Share on other sites More sharing options...
wisewood Posted March 22, 2006 Share Posted March 22, 2006 splitting the results into two columns as follows;1 | 23 | 45 | 67is straight forward... but i'm looking for a way to do;1 | 52 | 63 | 74 |and haven't figured out how to do it yet.If you find anything, please let me know... Quote Link to comment Share on other sites More sharing options...
Switch0r Posted March 22, 2006 Author Share Posted March 22, 2006 well ill explain what ive got:a set of 25 records, for example, which is set out in 1 column, that i want to split into 2 columns (by way of a table) with records 1 - 13 in column 1, and 14 - 25 in column 2. but the record set is variable in length, so i though by halfing the record number and rounding it up, then taking that away from the total would give numbers corresponding to the records.that in itself works ok, its outputting the records to the browser that im having trouble with.hope this makes it a bit clearer? Quote Link to comment Share on other sites More sharing options...
craygo Posted March 22, 2006 Share Posted March 22, 2006 Here you go, try this out. Will have to chenge some layout stuff but you should get the idea[code]<?php// Make DB connection here//set number of columns here$numcols = 2; // how many columns to display$numcolsprinted = 0; // no of columns so far// get the results to be displayed$query = "SELECT * FROM tablename";$mysql_result = mysql_query($query) or die (mysql_error());// get each rowwhile($myrow = mysql_fetch_row($mysql_result)){//get data - eg, reading fields 0 and 1$tn = $myrow[0];$in= $myrow[1];if ($numcolsprinted == $numcols) {print "</tr>\n<tr>\n";$numcolsprinted = 0;}// output row from databaseecho "<td>$in $tn</td>\n";// bump up row counter$numcolsprinted++;} // end while loop$colstobalance = $numcols - $numcolsprinted;for ($i=1; $i<=$colstobalance; $i++) {}print "<TD></TD>\n";?>[/code]Hope that worksRay Quote Link to comment Share on other sites More sharing options...
Switch0r Posted March 23, 2006 Author Share Posted March 23, 2006 cheers craygo, not entirely sure what all that meant, but i figured it out all by my lonesome anyway (one to tell the grandkids i reckon!)just put all the records into an array, and looped through the array to display the info. i cant believe i didnt think of it before really :) Quote Link to comment 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.