ashton321 Posted March 20, 2009 Share Posted March 20, 2009 Hello, I am trying to dived a list of data into 3 equal columns. Currently the only way i can think to do it is do each item as its own cell in its own list. However i know this adds a lot of unneeded coded and can be done much more efficiently. This is what i have: <?php echo '<table width="800" align="center" cellpadding="0" cellspacing="5">'; $i = 0; $max_columns = 3; while($result = mysql_fetch_array( $data )) { // make the variables easy to deal with extract($result); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($id != "" && $id != null){ echo '<td> <ul> <li>' . $service . '</li> </ul> </td>'; } // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; exit; } ?> . Any help or suggestions would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/ Share on other sites More sharing options...
iarp Posted March 21, 2009 Share Posted March 21, 2009 You could try todo that with div's but then you'd only end up with more then double the coding and trouble of changing everything, and testing. I'd say your best bet, and easiest is to stick with tables. Less coding and all browsers(to my knowledge) are fully compatible with html tables. Quote Link to comment https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/#findComment-789993 Share on other sites More sharing options...
ashton321 Posted March 21, 2009 Author Share Posted March 21, 2009 OK i will just keep what i have since it works. I just thought that there would be a more efficient way. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/#findComment-790032 Share on other sites More sharing options...
redarrow Posted March 21, 2009 Share Posted March 21, 2009 I got the same problem mate, When it comes to designing good looking web sites, I also use tables heavily and inline css. Arther reading for a long time yesterday about css and xhtml, I am gooing to change all my web design skills towards xhtml/css. If you look in your local paper for a programming job, your notice they want the lot, xhtml css 1 2 3 psudo code aswell ajax javascript php mysql seo It a lot to take on board man. I suggest converting to the same as me in the future and study up to date web design structure. and good luck nice code. Quote Link to comment https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/#findComment-790036 Share on other sites More sharing options...
ashton321 Posted March 21, 2009 Author Share Posted March 21, 2009 Yeah thanks for the support. I'm going to buy some books on css and xhtml. I am completely self taught so my style and techniques are the greatest and i know that it is because i didnt learn the right way. I only ever wanted it to work, but now i hae to go bad a learn again. Quote Link to comment https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/#findComment-790297 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.