Hi there, hope you can help here.

I basically want to output my list of products into a table, but display 5 products per table row.

e.g.

"Product1, Product2, Product3, Product4, Product5"
"Product6, Product7, Product8, Product9, Product10"

At the moment the code works but I am outputting 1 product per row.

e.g.

"Product1"
"Product2"
"Product3" etc

Here is the PHP code I have got (I didn't write it so I need to customise it to do this).

Anyone have an idea?:


require_once "$ds_path/lib/database.inc";

$products = get_products($db, stripslashes($ds_query), '' , 1, get_post_meta($post->ID, 'ds_title', true), get_option('ds_clickref'));

$permalink = get_permalink();
echo get_post_meta($post->ID, 'ds_title', true);

echo('<div style="clear:both"><table class="pricebox">');

foreach ($products as $product) {

if (str_startswith($product['deep_link'], 'http')) {
$deep_link = $product['deep_link'];
} else {

if (! $ds_redirect_url) {
$ds_redirect_url = $ds_url;
}

$deep_link = $ds_redirect_url . '/' . $product['deep_link'];
}

echo <<<EOHTML
<td>
<a href="$deep_link"><img src="{$product['image_url']}" border="0" alt="" width="100" height="100" /></a>
<p><strong>{$product['name']}</strong><br /><a target="_{$product['mykey']}" href="$deep_link"><strong>$CURRENCY_PREFIX{$product['display_price']}</strong></a><br /><a href="$deep_link"><img src="http://www.myurl.com/images/more.gif" border="0"/></a>

</td>

EOHTML;

}

echo('</table></div>');

}

Many Thanks

    Hey thelightphp,

    When you do this, you will have to output the products in a loop, create a variable "i" which stores the number of iterations, and then simply, when the iteration % 5 == 0 end the table row:

    <?php

    $html = '<table>';

    for($i=0;$i<$totalProducts;$i++)
    {
    if($i%5 == 0)
    {
    $html .= '<tr>'; //start table row
    }

     $html .= '<td> PRODUCT GOES HERE </td>';
    
     if($i%5 == 0 && $i>0)
     { 
          $html .= '</tr>'; //end table row
     }

    }

    ?>

    I just roughly created that script above, I didn't even check for errors, but experiment with that and I'm sure you'll get it

      Hi there Moharo, thank you very much for this, I will give it a go!

      Thanks🙂

        3 months later

        I also have a problem like this...I have to display items in a column and he next fiven in the second column.like:-

        1 5
        2 6
        3 7
        4 8
        5 9

        Please help me ..!!!

          Write a Reply...