SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    vertical to horizontal do-while reformat

    This outputs on the vertical. (There is an indefinite number of results, but would like 3 columns.) Looking to make these results appear not as:

    1 | 3 | 5
    2 | 4 | 6

    But:

    1 | 2 | 3
    4 | 5 | 6

    PHP Code:
    <table width="" border="0" cellspacing="0" cellpadding="0">
    <?php 
    $tdcount
    =0
    do { 
    $tdcount++; 
    if (
    $tdcount==4) { $tdcount=1; } 
    if (
    $tdcount==1) { echo '<tr>'; } 
    ?> 
    <td valign="top"> 
    <table align="center"> 
    <tr> <td width="110" height="20" style="background-color:#<? echo 
    $row_ALLCalstyle['CLHex']; ?>;"><div align="center"><font color="#666666" size="2" 
    face="Arial, Helvetica, sans-serif"><? echo $row_ALLCalstyle['assigned_sname']; 
    ?></font></div></td>
    </tr>
    </table> 
    </td> 
    <?php 
    if ($tdcount==3) { echo '</tr>'; } 
    } while (
    $row_ALLCalstyle mysql_fetch_assoc($ALLCalstyle)); 
    ?>
    </table>
    Last edited by datadriven; Dec 20, 2005 at 13:25.

  2. #2
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to add a counter to your script to keep check on how many cells have been created and then drop in a new row where required.

    I use the following code to display a bunch of thumbnails in a table with 7 cells per row.

    You should be able to tailor this to whatever you need.

    PHP Code:
    <table>
    <?
    $column 
    0;

    while (
    $imagelist mysql_fetch_array($offerimagelist)) {
        
    $imageID    $imagelist["ID"];
        
    $imagename    $imagelist["ImageName"];
        
    $imageURL    $imagelist["ImageURL"];
        
        { if (
    $column == 0) { 

    //change the colspan to how many cells you want

    echo("<tr><td colspan=\"7\" height=\"1\"><hr size=\"1\"></td></tr><tr>" );
     }
          
    ?>
        <td align="center">
        <img src="<?php echo $domainURL $imageURL;?>" height="50" width="75" />

        </td>

        <?php 

        $column
    ++; 

         if (
    $column >= 7//change this figure to how many cells you want


     
    $column 0; echo("</tr>" );
        
        }
        }
        
        } 
    //end image loop
        
    ?>
      </table>

  3. #3
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks elgumbo,

    still looking at, but it looks like what I need.

    (something came up today, possibly setting launch date of site back (1) week so I must tend to it.)

    thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •