Jump to content

Recommended Posts

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. 

Link to comment
https://forums.phpfreaks.com/topic/150400-solved-dividind-lists-into-columns/
Share on other sites

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.

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.

 

 

 

 

 

 

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.