how can I display my data in four columns?

Discussion in 'PHP' started by paul1957, Jul 15, 2007.

  1. #1
    I have 28 rows of data, i know how to display the data.

    The problem is that it lists the data in one column, I would like to display the 28 items within FOUR columns, equally.

    In the future I'll have more than 28 rows...

    data data data data
    data data data data
    data data data data
    data data data data

    Again, i would like the columns to contain the same amount of items, (unless it's an odd number of course)

    Thanks!
     
    paul1957, Jul 15, 2007 IP
  2. technoguy

    technoguy Notable Member

    Messages:
    4,395
    Likes Received:
    308
    Best Answers:
    0
    Trophy Points:
    205
    #2
    are you fetching data from database? you can use mod operator like $i%4 == 0 then </tr>

    thanks
     
    technoguy, Jul 15, 2007 IP
  3. paul1957

    paul1957 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is the code i'm using (php and mysql)

    
    <?php
    
    while($row = mysql_fetch_array($result)){
    
    
    
    echo "<div id='sitetitle'>". $sitetitle. "</div>";
    
    echo "<a href='". $loginurl. "'>L</a> | <a href='". $registerurl. "'>R</a> | <a href='". $phplink. "'>". $sitetitle. "</a><br><br>";
    
    }
    
    ?>
    
    
    PHP:
     
    paul1957, Jul 15, 2007 IP
  4. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #4
    i'm using this code to show my template names in 4 columns. Though it's a long process i think it may help you. Please let me know if you can use it :)


    <table align="center" width="100%" cellpadding="2" cellspacing="0" border="0">
    <tr>
    <td colspan="4">Latest Templates</td>
    </tr>
    <?
    $r = mysql_query("select * from product order by product_add_date desc");
    for($i=0; $i < ceil(mysql_num_rows($r)/4); $i++){
    $w = mysql_fetch_array($r);
    $tplID = $w['product_id'];
    $tplName = $w['product_name'];

    ?>
    <tr>
    <td width="130" valign="top">
    <?=$tplID?> - <?=$tplName?>
    </td>
    <?
    $w = mysql_fetch_array($r);
    $tplID = $w['product_id'];
    $tplName = $w['product_name'];

    if($tplID != ""){

    ?>
    <td width="130" valign="top">
    <?=$tplID?> - <?=$tplName?>
    </td>
    <? }


    $w = mysql_fetch_array($r);
    $tplID = $w['product_id'];
    $tplName = $w['product_name'];


    if($tplID != ""){
    ?>
    <td width="130" valign="top">
    <?=$tplID?> - <?=$tplName?>
    </td>
    <? }

    $w = mysql_fetch_array($r);
    $tplID = $w['product_id'];
    $tplName = $w['product_name'];

    if($tplID != ""){
    ?>
    <td width="130" valign="top">
    <?=$tplID?> - <?=$tplName?>
    </td>
    <? } ?>
    </tr>
    <tr><td colspan="4">&nbsp;</td></tr>
    <?
    }
    ?>
    </table>
     
    srobona, Jul 16, 2007 IP
    rightit likes this.
  5. Kongtechnology

    Kongtechnology Guest

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Below is a piece of code which I use for a gallery page. It's lightly modified, hope you can use it.

    
    						echo "<table width=100% cellspacing=1 cellpadding=6>";
    						while($query_data = mysql_fetch_array($result)) {
    							if($i==0 || $i % 4==0) {
    								echo "<tr align=center valign=top bgcolor=DFE7FF>";
    							}
    							echo "<td width=25%>&nbsp;";
    							echo "<a href='index.php?id=".$query_data["event_id"]."&im=photo_gallery_d' class=blue>".$query_data["event"]."</a></td>";
    		
    							if($i != 0 && ($i+1) % 4==0) {
    								echo "</tr>";
    							}
    							$i = $i + 1;
    						}
    		
    						//fill up blank TDs
    						$blank = false;
    						for(; ($i%4 != 0); ) {
    							echo "<td>&nbsp;</td>";
    							$i = $i + 1;
    							$blank = true;
    						}
    						if($blank)
    							echo "</tr>";
    						//fill up blank TDs
    		
    						echo "</table>";
    
    PHP:
     
    Kongtechnology, Jul 16, 2007 IP