Hey folks,

I found the answers to many variations of this question, but have found nothing to answer this particular issue. Perhaps you can provide some guidance.

What I have is an array that I wish to display as 3 columns in an HTML table. If the values in the array were ascending integers, the table should look like this:

| 1 | 4 | 7 |
| 2 | 5 | 8 |
| 3 | 6 | 9 |

Currently the only result I can get that's close is...

| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |

I can get the table to behave if it were only two columns (sorting ascending by column), but I'm stumped on how to get the results I need in three columns.

Any direction you can provide is much appreciated.

Regards,

TS

    Try this

    <table>
    <tr>
    <td>value 1</td>
    <td>value 4</td>
    <td>value 7</td>
    </tr>
    <tr>
    <td>value 2</td>
    <td>value 5</td>
    <td>value 8</td>
    </tr>
    <tr>
    <td>value 3</td>
    <td>value 6</td>
    <td>value 9</td>
    </tr>
    </table>

    all you are doing is plugging the values into the table where you want them....
    <tr> ir table row
    <td> is the column in the row.

    hope this helps.

      Thanks for taking the time to give me hand. I do appreciate it.

      The problem for me is that my array will grow in size, so the table would have to be dynamic in nature. What I'm struggling with is how to incorporate this into a loop so it's done on the fly.

      Best,

      TS

        Is there a max X or Y value for the rows or columns?

        do your array sort
        devied the total number of data values by 3
        wile value < total numbe of data values
        start the loop
        add row1
        add columm value a
        add column value b=value a+(total/3)
        add column value c=value b +(total/3)
        value a= value a+1
        next loop

        That should incriment each colum in the row so that the values incriment in the colums instead of the rows

          Okay, while it's not the most elegant solution I'm sure... here's what worked for me. The name of the array I want to split into three columns is '$names'. The goal was to create the appropriate url for each item in the array.

          Cheers!

          TS

          
          $R = ceil(count($names) / 3);  // 3 cols, round up
          
          echo "<table>";
          
          $f1="<TD>\n";
          $f2="</TD>\n";
          
          for ($i=0; $i < $R; $i++) {
          
          echo '<TR>';
          
          $s=$names[$i];
          $utitle=urlencode($s);
          echo $f1."<a href=\"http://www.mysite.com/titles.php?name=$utitle\">$s</a>".$f2;
          
          $s=$names[$i+$R];
          $utitle=urlencode($s);
          echo $f1."<a href=\"http://www.mysite.com/titles.php?name=$utitle\">$s</a>".$f2; 
          
          $s=$names[$i+2*$R];
          $utitle=urlencode($s);
          echo $f1."<a href=\"http://www.mysite.com/titles.php?name=$utitle\">$s</a>".$f2; 
          
          echo '</TR>';
          
          }
          
          echo "</table>";
          
          
            Write a Reply...