views:

98

answers:

1

I have a pretty simple question, but for some reason I am drawing a blank. I have the following code in my view file, and I want to display the results in a two column table, so the first entry would be on the left, the next would be on the right then the next one after that would be below the first row, and eventually I will use the pagination class (haven’t gotten that far yet) For some reason I can not figure out how to get the results to display in a 2 column format… only one. Any help would be greatly appreciated.

Ideally I would like to have 4 columns, but the code below was started with just the idea of 2 columns. Thanks!

<table>

db->query($sql); foreach ($query->result() as $row) { echo(""); echo("");

        echo $row->Title;
        echo ("<br/>");
        ?>
        <img name="<?php echo $row->Thumb;?>" src="../uploaded/portfolio/thumbs/<?php echo $row->Thumb;?>"   alt="">
        <?php
        echo("<br/>");
        echo $row->DescText;
    echo("</td>");
    echo("<td>");

    // Display next picture here
    echo("</td>");
    echo("</tr>");
    }
    ?>

../

A: 

Your code example is rather confusing, but I think from your description that you're trying to do something like this:

<table>
  <tr>

  <?php $i = 0; foreach($query->result() as $row): ?>   

    <?php if ($i % 2 == 0): ?>
      </tr><tr>
    <?php endif; ?>

    <td>
      <?php //whatever you want to put in your column goes here; ?>
    </td>

   <?php $i++; endforeach; ?>
  </tr>
</table>

If you want the table to be four rows across, just change the "if ($i % 2 == 0)" to "if ($i % 4 == 0)".

caseyamcl