Steve Elford - 2007-10-22

HI there.

I'm quite new to PHP so I hope someone can help me with this.

In my excel doc I have 3 columns: Image Filename, Description, Price

Basically, I want to display the information from each row in a single cell of an HTML table that has 4 columns. Like this:

1    2     3    4
5    6     7    8
9   10  11  12
13  14  15  16

...and so on.

I've managed it with 2 columns using odd and even numbers, like this:

<?

$pg= 2 //sheet number

$startRow = 3;
$cells = $data->sheets[$pg]['cells'];

// GET TOTAL NUMBER OF rows
$count_pic=$data->sheets[$pg]['numRows'];

// CHECK IF TOTAL NUMBER IS ODD OR EVEN
$qty = "2"; // NUMBER OF TABLE COLUMNS
if ($count_pic % $qty!= 0) {$even="0";} else {$even="1";}

echo "
<table id='product_grid' width='100%' border='0' cellpadding='0' cellspacing='0'>";

for($row=$startRow;$row<=$data->sheets[$pg]['numRows'];$row++){
    $Desc = htmlentities($cells[$row][1]);
    $Price = htmlentities($cells[$row][2]);
    $Filename = $cells[$row][3];

    // OPEN TR IF COUNT IS AN ODD NUMBER
    if($row % $qty!= 0) {echo '<tr>';}
   
echo "<td><a class=\&quot;thickbox\&quot; rel=\&quot;group\&quot; href=\&quot;images/product_images/designer/ellen_faith/fullsize/" . $Filename . "\&quot;><img src=\&quot;images/product_images/designer/ellen_faith/thumbnails/" . $Filename . "\&quot; width=\&quot;100\&quot; height=\&quot;100\&quot; /></a><br />" . $Desc . "<br />" . $Price . "</td>";

// CLOSE TR IF COUNT IS AN EVEN NUMBER
if($row % $qty == "0") {echo '</tr>';}
}
// IF COUNT_PIC IS ODD, THEN ADD EMPTY <td></td>
if($even=="0") {echo '<td></td></tr>';}

echo "</table>";

?>

I can't figure out how to do 4 columns though. Any ideas?

Many thanks in advance.