scvinodkumar Posted February 27, 2009 Share Posted February 27, 2009 HI there, I have to display 100 records, but needs to align in three column how to do this in php? please help me Quote Link to comment https://forums.phpfreaks.com/topic/147224-three-column-layout/ Share on other sites More sharing options...
lonewolf217 Posted February 27, 2009 Share Posted February 27, 2009 php doesn't display data. use CSS to organize how your page is layed out. once that is figured out you can use PHP to echo the data to the proper location. Quote Link to comment https://forums.phpfreaks.com/topic/147224-three-column-layout/#findComment-772910 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 please post if u have already tried some code... Quote Link to comment https://forums.phpfreaks.com/topic/147224-three-column-layout/#findComment-772917 Share on other sites More sharing options...
daviddth Posted February 28, 2009 Share Posted February 28, 2009 I have to display 100 records, but needs to align in three column Assuming you dont want a CSS style setup, but plain html, then it is relatively easy. Here is the crux of a bit of my code that displays a variable across (in order) on a 4 column format. Is it elegant? Heck no, but it works and works really well. I'd love to have others pick it apart as my 2 week knowledge of php & mySQL is growing, but only to solve problems I encounter like this lol. I have added a few comments to the code to explain it. echo '<div align="center"><table border="1">'; $tcount=1; while ($row2 = mysql_fetch_assoc($result2)) { if ($tcount==1) echo('<tr><td>'); // start of line else echo('<td>'); // if it's not 1 then it's the next echo('<a href="index.php?pid=2&Shortname='.$row2["Shortname"].'">'.$row2["Shortname"].'</a></td>'); // DOnt be worried - just the required bit of info on the screen $tcount++; if ($tcount==5) { //i.e. if tcount is 1 greater than the number of columns you want in the table, reset it and put the end of row $tcount=1; echo ('</tr>'); } } //this bit fills in and blank table boxes with non blanking spaces at the bottom of the table just to make it nice & neat if ($tcount>1) { while ($tcount<5) { echo('<td> </td>'); $tcount++; } } echo ('</tr></table></div><br>'); // close the table Quote Link to comment https://forums.phpfreaks.com/topic/147224-three-column-layout/#findComment-773003 Share on other sites More sharing options...
laffin Posted February 28, 2009 Share Posted February 28, 2009 this kinda depends how u want the data displayed 1-33 in col1 34-66 in col 2 66-99 in col 3 or in an across type table 1,4,7,10,..... in col1 2,5,8,11,.... in col2 3,6,9,12,.... in col3 in first style its all about the math. $cols=3; $max=100 for($i=0;$i<$max;$i++) $ar[$i]=$i; echo "<TABLE>"; for($i=$ctr=0;$i<$max;$i++) { if($ctr=0) echo "<TR>"; echo "<TD>".$ar[$i]."</TD>"; $ctr++; if($ctr>=$cols) { $ctr=0; echo "</TR>" } } while($ctr && $ctr++<$cols) echo "<TD> </TD>"; if($ctr) echo "</TR>"; echo "</TABLE>"; The other way having the info on per row is same concept, but our counters change as well as the when the display code changes [code] $cols=3; $max=100 for($i=0;$i<$max;$i++) $ar[$i]=$i; echo "<TABLE>"; for($i=$ctr=0;$i<$max;$i++) { if($ctr=0) echo "<TR><TD>"; echo $ar[$i]."<BR>"; $ctr++; if($ctr>=$percol) { $ctr=0; echo "</TD></TR>" } } if($ctr) echo "</TD></TR>"; echo "</TABLE>"; I think that shud do it, but this code is just from scratch, but ya shud get the idea from both examples Quote Link to comment https://forums.phpfreaks.com/topic/147224-three-column-layout/#findComment-773013 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.