0

I have the following code section that is used for displaying a list of items and would like to modify it so it displays as a multi column display.

I have been told that I need to use a counter, but I cannot find any information on how to do this. - Can anybody here help me with this, please, or point to an existing article with the relevant information in it?

// +--
// | Loop through the products.
// +--

foreach ($prodlist as $num => $prod) {

      // +--
      // | Print a table row opener.
      // +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

      // +--
      // | Print the tds and their content.
      // +--

      $prodname  = $this->xhtml_encode($prod['name']);
      $prodid    = $this->xhtml_encode($prod['id']);
      $prodlink  = $this->link_namespace($app,'prodshow',$prod['id']);
      $proddesc  = $this->xhtml_encode($prod['descshort']);
      $imgname   = $prod['imgsm'];

      $add_ok = 1;

      if (($prod['useinv']) && (!($prod['invlevel'] > 0))) {$add_ok = 0;}
      if ($prod['pricestatus'] == 'D') {$add_ok = 0;}

      $quandisp = 0;
      $quanform = $this->globals('khxc_cgi.' . $formid . '--' . $prodid . '--quantity');

      if (isset($quanform)) {$quandisp = $quanform;}

      if ($add_ok) {

           print '<td class="' . $tdclass . '">' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<input class="khxc_formfield" type="text" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" size="5" maxlength="5" />' . $eol;
           print '</td>' . $eol . $eol;

      } else {

           print '<td class="' . $tdclass . '">&nbsp;' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<p class="hidden"><input type="hidden" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" /></p>' . $eol;
           print '</td>' . $eol . $eol;

      } // End of if statement.
      $image_ok = 0;

      if ((!(empty($imgname))) && ($imgname != 'none.png')) {$image_ok = 1;}

      if ($image_ok) {

           $imgurl   = 'media/' . $app . '/prodsm/' . $imgname;
           $imgtag   = '<a href="' . $prodlink . '" title="' . $prodname . '">';
           $imgtag  .= '<img src="' . $imgurl . '" ';
           if ($imgwidth) {$imgtag .= 'width="' . $imgwidth . '" ';}
           $imgtag  .= 'alt="' . $prodname . '" /></a>';

           print '<td class="' . $tdclass . '">' . $imgtag . '</td>' . $eol . $eol;

      } else {

          if ($multi_images) {

               print '<td class="' . $tdclass . '">&nbsp;</td>' . $eol . $eol;

          } // End of if statement.

      } // End of if statement.

      print '<td class="' . $tdclass . '">';

      print '<p><a href="' . $prodlink . '" title="' . $prodname . '">';
      print $prodname . '</a></p>' . $eol;

      if (!(empty($proddesc))) {print '<p>' . $proddesc . '</p>' . $eol;}

      $this->globals('ecom.prod_proddisp',$prod);
      $this->globals('ecom.prod_priceinfo',$prod['khxc.priceinfo']);
           
      $this->include_file($app,'pricedisp.php');

      if ($add_ok) {

            $this->include_namespace($app,'prodshowoptlite',array('form' => $formid . '--' . $prodid, 'showquan' => 0, 'headfoot' => 0));

      } // End of if statement.

      print '</td>' . $eol . $eol;

      // +--
      // | Close the table row.
      // +--

      print '</tr>' . $eol . $eol;

} // End of foreach statement.
2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by JBLDW
0

I'd suggest a simple variable that increments with each iteration of the foreach loop. With something like the code below, you can access the number of the element with the counter variable.

// +--
// | Loop through the products.
// +--

$counter = 0; //Init the counter

foreach ($prodlist as $num => $prod) {
      //Leave the below line at the top of the loop
      $counter++; //Increment the counter with each product
                  //The counter starts at 1 and counts up

      // +--
      // | Print a table row opener.
      // +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

      // +--
      // | Print the tds and their content.
      // +--

      $prodname  = $this->xhtml_encode($prod['name']);
      $prodid    = $this->xhtml_encode($prod['id']);
      $prodlink  = $this->link_namespace($app,'prodshow',$prod['id']);
      $proddesc  = $this->xhtml_encode($prod['descshort']);
      $imgname   = $prod['imgsm'];

      $add_ok = 1;

      if (($prod['useinv']) && (!($prod['invlevel'] > 0))) {$add_ok = 0;}
      if ($prod['pricestatus'] == 'D') {$add_ok = 0;}

      $quandisp = 0;
      $quanform = $this->globals('khxc_cgi.' . $formid . '--' . $prodid . '--quantity');

      if (isset($quanform)) {$quandisp = $quanform;}

      if ($add_ok) {

           print '<td class="' . $tdclass . '">' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<input class="khxc_formfield" type="text" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" size="5" maxlength="5" />' . $eol;
           print '</td>' . $eol . $eol;

      } else {

           print '<td class="' . $tdclass . '">&nbsp;' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<p class="hidden"><input type="hidden" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" /></p>' . $eol;
           print '</td>' . $eol . $eol;

      } // End of if statement.
      $image_ok = 0;

      if ((!(empty($imgname))) && ($imgname != 'none.png')) {$image_ok = 1;}

      if ($image_ok) {

           $imgurl   = 'media/' . $app . '/prodsm/' . $imgname;
           $imgtag   = '<a href="' . $prodlink . '" title="' . $prodname . '">';
           $imgtag  .= '<img src="' . $imgurl . '" ';
           if ($imgwidth) {$imgtag .= 'width="' . $imgwidth . '" ';}
           $imgtag  .= 'alt="' . $prodname . '" /></a>';

           print '<td class="' . $tdclass . '">' . $imgtag . '</td>' . $eol . $eol;

      } else {

          if ($multi_images) {

               print '<td class="' . $tdclass . '">&nbsp;</td>' . $eol . $eol;

          } // End of if statement.

      } // End of if statement.

      print '<td class="' . $tdclass . '">';

      print '<p><a href="' . $prodlink . '" title="' . $prodname . '">';
      print $prodname . '</a></p>' . $eol;

      if (!(empty($proddesc))) {print '<p>' . $proddesc . '</p>' . $eol;}

      $this->globals('ecom.prod_proddisp',$prod);
      $this->globals('ecom.prod_priceinfo',$prod['khxc.priceinfo']);
           
      $this->include_file($app,'pricedisp.php');

      if ($add_ok) {

            $this->include_namespace($app,'prodshowoptlite',array('form' => $formid . '--' . $prodid, 'showquan' => 0, 'headfoot' => 0));

      } // End of if statement.

      print '</td>' . $eol . $eol;

      // +--
      // | Close the table row.
      // +--

      print '</tr>' . $eol . $eol;

} // End of foreach statement.
0

Thank-you, FlashCreations, that looks to be exactly what I need and has already fixed a problem with multiple looping that I was having with a different attempted fix.

I have just tried to use the count value to split the display for the multi-column display, but this is not working at the moment...

// +--
      // | Print a table row opener.
      // +--

	if ($counter >= 1) {

	print '<tr>';

	}

...so I have now posted the entire code to (hopefully) make it easier for anyone else wanting to give me advice on modifying it:

<?php 

$app       = $this->globals('khxc_display.app');
$ns        = $this->globals('khxc.namespace');
$ref       = $this->globals('khxc.ref');
$eol       = $this->globals('khxc.eol');
$prodlist  = $this->globals('ecom.prod_prodlist');
$navarray  = $this->globals('ecom.prod_navarray');
$imgwidth  = $this->globals('khxc_settings.' . $app . '.imgsizeprodsm');
$disablewl = $this->globals('khxc_settings.' . $app . '.disablewishlist');

$supsort   = $this->globals('ecom.prod_suppress_sort');
$showsort  = $this->globals('khxc_settings.' . $app . '.showsortopts');

$catshow = $this->globals('ecom.cat_catshow');
$catid = $catshow['id'];

$columns = 2;

if ($catid == 'test') {

$prodcount = count($prodlist);

// +--
// | In this step we determine whether we will be showing
// | images in this display.
// +--

$multi_images = 0;

foreach ($prodlist as $num => $prod) {

     if ((!(empty($prod['imgsm']))) && ($prod['imgsm'] != 'none.png')) {$multi_images = 1;}

} // End of foreach statement.

// +--
// | Define the header text.
// +--

$header   = $this->globals('ecom.prod_store_header');

if (empty($header)) {

     if ($ns == 'prodshow') {$header = 'Related Items';} else {$header = 'Items';}

} else {

     $header .= ' Featured Items';

} // End of if statement.

$header   = $this->xhtml_encode($header);

$random  = 'x' . $this->random_key(8);

// +--
// | Print the products header.
// +--

print '<div class="khxc_storehead">' . $header . '</div>' . $eol . $eol;

// +--
// | Print the form opener.
// +--

$nsid     = 'ns';
$formid   = $app . '--prodaddtocartM';

$this->xhtml_quickform_header($formid,$app,'addcart',array($nsid => $ns));

// +--
// | Print multi-add table header.
// +--

if (empty($disablewl)) {

print '';

} else {

     print '';

} // End of if statement.

print '<table id="khxc--cptbl--' . $random . '" class="khxc_sorttable">' . $eol . $eol;

$trclass = 'khxc_sorttable';
$tdclass = 'khxc_sorttable';

print '<tr class="khxc_sorttable">' . $eol . $eol;
print '<th class="khxc_sorttable">Quantity</th>' . $eol;

if ($multi_images) {

     print '<th class="khxc_sorttable"><p class="hidden">Image</p></th>' . $eol;
     print '<th class="khxc_sorttable">Item</th>' . $eol;

} else {

print '<th class="khxc_sorttable">Item</th>' . $eol;

} // End of if statement.

print '</tr>' . $eol . $eol;

// +--
// | Loop through the products.
// +--

$counter = 0; //Init the counter

foreach ($prodlist as $num => $prod) {
      //Leave the below line at the top of the loop
      $counter++; //Increment the counter with each product
                  //The counter starts at 1 and counts up

      // +--
      // | Print a table row opener.
      // +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

      // +--
      // | Print the tds and their content.
      // +--

      $prodname  = $this->xhtml_encode($prod['name']);
      $prodid    = $this->xhtml_encode($prod['id']);
      $prodlink  = $this->link_namespace($app,'prodshow',$prod['id']);
      $proddesc  = $this->xhtml_encode($prod['descshort']);
      $imgname   = $prod['imgsm'];

      $add_ok = 1;

      if (($prod['useinv']) && (!($prod['invlevel'] > 0))) {$add_ok = 0;}
      if ($prod['pricestatus'] == 'D') {$add_ok = 0;}

      $quandisp = 0;
      $quanform = $this->globals('khxc_cgi.' . $formid . '--' . $prodid . '--quantity');

      if (isset($quanform)) {$quandisp = $quanform;}

      if ($add_ok) {

           print '<td class="' . $tdclass . '">' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<input class="khxc_formfield" type="text" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" size="5" maxlength="5" />' . $eol;
           print '</td>' . $eol . $eol;

      } else {

           print '<td class="' . $tdclass . '">&nbsp;' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<p class="hidden"><input type="hidden" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" /></p>' . $eol;
           print '</td>' . $eol . $eol;

      } // End of if statement.
      $image_ok = 0;

      if ((!(empty($imgname))) && ($imgname != 'none.png')) {$image_ok = 1;}

      if ($image_ok) {

           $imgurl   = 'media/' . $app . '/prodsm/' . $imgname;
           $imgtag   = '<a href="' . $prodlink . '" title="' . $prodname . '">';
           $imgtag  .= '<img src="' . $imgurl . '" ';
           if ($imgwidth) {$imgtag .= 'width="' . $imgwidth . '" ';}
           $imgtag  .= 'alt="' . $prodname . '" /></a>';

           print '<td class="' . $tdclass . '">' . $imgtag . '</td>' . $eol . $eol;

      } else {

          if ($multi_images) {

               print '<td class="' . $tdclass . '">&nbsp;</td>' . $eol . $eol;

          } // End of if statement.

      } // End of if statement.

      print '<td class="' . $tdclass . '">';

      print '<p><a href="' . $prodlink . '" title="' . $prodname . '">';
      print $prodname . '</a></p>' . $eol;

      if (!(empty($proddesc))) {print '<p>' . $proddesc . '</p>' . $eol;}

      $this->globals('ecom.prod_proddisp',$prod);
      $this->globals('ecom.prod_priceinfo',$prod['khxc.priceinfo']);
           
      $this->include_file($app,'pricedisp.php');

      if ($add_ok) {

            $this->include_namespace($app,'prodshowoptlite',array('form' => $formid . '--' . $prodid, 'showquan' => 0, 'headfoot' => 0));

      } // End of if statement.

      print '</td>' . $eol . $eol;

      // +--
      // | Close the table row.
      // +--

      print '</tr>' . $eol . $eol;

} // End of foreach statement.

?>

I have also found another post: http://www.daniweb.com/forums/thread288497.html that references a similar problem, so I am studying that too for anything that might help with this.

Edited by JBLDW: n/a

0

I have just modified the code and amended it with a control on the counter, so that nothing should be preventing it from displaying in a multi-column format, as shown below, but it is still refusing to do so ...in fact, the array items are now being displayed in a long line right across the screen, so the <tr> tags are clearly not being applied:

<?php

$app       = $this->globals('khxc_display.app');
$ns        = $this->globals('khxc.namespace');
$ref       = $this->globals('khxc.ref');
$eol       = $this->globals('khxc.eol');
$prodlist  = $this->globals('ecom.prod_prodlist');
$navarray  = $this->globals('ecom.prod_navarray');
$imgwidth  = $this->globals('khxc_settings.' . $app . '.imgsizeprodsm');
$disablewl = $this->globals('khxc_settings.' . $app . '.disablewishlist');

$supsort   = $this->globals('ecom.prod_suppress_sort');
$showsort  = $this->globals('khxc_settings.' . $app . '.showsortopts');

$catshow = $this->globals('ecom.cat_catshow');
$catid = $catshow['id'];

$columns = 2;

// if ($catid == 'test') {

$prodcount = count($prodlist);

// +--
// | In this step we determine whether we will be showing
// | images in this display.
// +--

$multi_images = 0;

foreach ($prodlist as $num => $prod) {

     if ((!(empty($prod['imgsm']))) && ($prod['imgsm'] != 'none.png')) {$multi_images = 1;}

} // End of foreach statement.

// +--
// | Define the header text.
// +--

$header   = $this->globals('ecom.prod_store_header');

if (empty($header)) {

     if ($ns == 'prodshow') {$header = 'Related Items';} else {$header = 'Items';}

} else {

     $header .= ' Featured Items';

} // End of if statement.

$header   = $this->xhtml_encode($header);

$random  = 'x' . $this->random_key(8);

// +--
// | Print the products header.
// +--

print '<div class="khxc_storehead">' . $header . '</div>' . $eol . $eol;

// +--
// | Print the form opener.
// +--

$nsid     = 'ns';
$formid   = $app . '--prodaddtocartM';

$this->xhtml_quickform_header($formid,$app,'addcart',array($nsid => $ns));

// +--
// | Print multi-add table header.
// +--

if (empty($disablewl)) {

print '';

} else {

     print '';

} // End of if statement.

print '<table id="khxc--cptbl--' . $random . '" class="khxc_sorttable">' . $eol . $eol;

// +--
// | Loop through the products.
// +--





$counter = 0;


foreach ($prodlist as $num => $prod) {
      //Leave the below line at the top of the loop
      $counter++; //Increment the counter with each product
                  //The counter starts at 1 and counts up

      // +--
      // | Print a table row opener.
      // +--

      // print '<tr class="' . $trclass . '">' . $eol . $eol;

      // +--
      // | Print the tds and their content.
      // +--

      $prodname  = $this->xhtml_encode($prod['name']);
      $prodid    = $this->xhtml_encode($prod['id']);
      $prodlink  = $this->link_namespace($app,'prodshow',$prod['id']);
      $proddesc  = $this->xhtml_encode($prod['descshort']);
      $imgname   = $prod['imgsm'];

      $add_ok = 1;

      if (($prod['useinv']) && (!($prod['invlevel'] > 0))) {$add_ok = 0;}
      if ($prod['pricestatus'] == 'D') {$add_ok = 0;}

      $quandisp = 0;
      $quanform = $this->globals('khxc_cgi.' . $formid . '--' . $prodid . '--quantity');

      if (isset($quanform)) {$quandisp = $quanform;}

      if ($add_ok) {

           print '<td class="' . $tdclass . '">' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<input class="khxc_formfield" type="text" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" size="5" maxlength="5" />' . $eol;
           print '</td>' . $eol . $eol;

      } else {

           print '<td class="' . $tdclass . '">&nbsp;' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<p class="hidden"><input type="hidden" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" /></p>' . $eol;
           print '</td>' . $eol . $eol;

      } // End of if statement.
      $image_ok = 0;

      if ((!(empty($imgname))) && ($imgname != 'none.png')) {$image_ok = 1;}

      if ($image_ok) {

           $imgurl   = 'media/' . $app . '/prodsm/' . $imgname;
           $imgtag   = '<a href="' . $prodlink . '" title="' . $prodname . '">';
           $imgtag  .= '<img src="' . $imgurl . '" ';
           if ($imgwidth) {$imgtag .= 'width="' . $imgwidth . '" ';}
           $imgtag  .= 'alt="' . $prodname . '" /></a>';

           print '<td class="' . $tdclass . '">' . $imgtag . '</td>' . $eol . $eol;

      } else {

          if ($multi_images) {

               print '<td class="' . $tdclass . '">&nbsp;</td>' . $eol . $eol;

          } // End of if statement.

      } // End of if statement.

      print '<td class="' . $tdclass . '">';

      print '<p><a href="' . $prodlink . '" title="' . $prodname . '">';
      print $prodname . '</a></p>' . $eol;

      if (!(empty($proddesc))) {print '<p>' . $proddesc . '</p>' . $eol;}

      $this->globals('ecom.prod_proddisp',$prod);
      $this->globals('ecom.prod_priceinfo',$prod['khxc.priceinfo']);
           
      $this->include_file($app,'pricedisp.php');

      if ($add_ok) {

            $this->include_namespace($app,'prodshowoptlite',array('form' => $formid . '--' . $prodid, 'showquan' => 0, 'headfoot' => 0));

      } // End of if statement.

      print '</td>' . $eol . $eol;

      // +--
      // | Close the table row.
      // +--

      //print '</tr>' . $eol . $eol;

} // End of foreach statement.


if ($counter == 5) {

      // +--
      // | Close the table row.
      // +--

      print '</tr>' . $eol . $eol;

// +--
// | Print a table row opener.
// +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

$counter = 0;
}

?>

Edited by JBLDW: n/a

0

This is the working code. - It has the counter with foreach statement and outputs the display in two columns:

<?php 

$app       = $this->globals('khxc_display.app');
$ns        = $this->globals('khxc.namespace');
$ref       = $this->globals('khxc.ref');
$eol       = $this->globals('khxc.eol');
$prodlist  = $this->globals('ecom.prod_prodlist');
$navarray  = $this->globals('ecom.prod_navarray');
$imgwidth  = $this->globals('khxc_settings.' . $app . '.imgsizeprodsm');
$disablewl = $this->globals('khxc_settings.' . $app . '.disablewishlist');

$supsort   = $this->globals('ecom.prod_suppress_sort');
$showsort  = $this->globals('khxc_settings.' . $app . '.showsortopts');

// $catshow = $this->globals('ecom.cat_catshow');
// $catid = $catshow['id'];

$columns = 2;

// if ($catid == 'test') {

$prodcount = count($prodlist);

// +--
// | In this step we determine whether we will be showing
// | images in this display.
// +--

$multi_images = 0;

foreach ($prodlist as $num => $prod) {

     if ((!(empty($prod['imgsm']))) && ($prod['imgsm'] != 'none.png')) {$multi_images = 1;}

} // End of foreach statement.

// +--
// | Define the header text.
// +--

$header   = $this->globals('ecom.prod_store_header');

if (empty($header)) {

     if ($ns == 'prodshow') {$header = 'Related Items';} else {$header = 'Items';}

} else {

     $header .= ' Featured Items';

} // End of if statement.

$header   = $this->xhtml_encode($header);

$random  = 'x' . $this->random_key(8);

// +--
// | Print the products header.
// +--

print '<div class="khxc_storehead">' . $header . '</div>' . $eol . $eol;

// +--
// | Print the form opener.
// +--

$nsid     = 'ns';
$formid   = $app . '--prodaddtocartM';

$this->xhtml_quickform_header($formid,$app,'addcart',array($nsid => $ns));

// +--
// | Print multi-add table header.
// +--

if (empty($disablewl)) {

print '';

} else {

     print '';

} // End of if statement.

print '<table id="khxc--cptbl--' . $random . '" class="khxc_sorttable">' . $eol . $eol;

      // +--
      // | Print a table row opener.
      // +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

// +--
// | Loop through the products.
// +--

$counter = 0;


foreach ($prodlist as $num => $prod) {
      //Leave the below line at the top of the loop
      $counter++; //Increment the counter with each product
                  //The counter starts at 1 and counts up

      // +--
      // | Print the tds and their content.
      // +--

      $prodname  = $this->xhtml_encode($prod['name']);
      $prodid    = $this->xhtml_encode($prod['id']);
      $prodlink  = $this->link_namespace($app,'prodshow',$prod['id']);
      $proddesc  = $this->xhtml_encode($prod['descshort']);
      $imgname   = $prod['imgsm'];

      $add_ok = 1;

      if (($prod['useinv']) && (!($prod['invlevel'] > 0))) {$add_ok = 0;}
      if ($prod['pricestatus'] == 'D') {$add_ok = 0;}

      $quandisp = 0;
      $quanform = $this->globals('khxc_cgi.' . $formid . '--' . $prodid . '--quantity');

      if (isset($quanform)) {$quandisp = $quanform;}

      if ($add_ok) {

           print '<td class="' . $tdclass . '">' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<input class="khxc_formfield" type="text" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" size="5" maxlength="5" />' . $eol;
           print '</td>' . $eol . $eol;

      } else {

           print '<td class="' . $tdclass . '">&nbsp;' . $eol . $eol;
           print '<label for="' . $formid . '--' . $prodid . '--quantity';
           print '" class="hidden">Quantity</label>' . $eol;
           print '<p class="hidden"><input type="hidden" name="';
           print $formid . '--' . $prodid . '--quantity';
           print '" id="' . $formid . '--' . $prodid . '--quantity';
           print '" value="' . $quandisp . '" /></p>' . $eol;
           print '</td>' . $eol . $eol;

      } // End of if statement.
      $image_ok = 0;

      if ((!(empty($imgname))) && ($imgname != 'none.png')) {$image_ok = 1;}

      if ($image_ok) {

           $imgurl   = 'media/' . $app . '/prodsm/' . $imgname;
           $imgtag   = '<a href="' . $prodlink . '" title="' . $prodname . '">';
           $imgtag  .= '<img src="' . $imgurl . '" ';
           if ($imgwidth) {$imgtag .= 'width="' . $imgwidth . '" ';}
           $imgtag  .= 'alt="' . $prodname . '" /></a>';

           print '<td class="' . $tdclass . '">' . $imgtag . '</td>' . $eol . $eol;

      } else {

          if ($multi_images) {

               print '<td class="' . $tdclass . '">&nbsp;</td>' . $eol . $eol;

          } // End of if statement.

      } // End of if statement.

      print '<td class="' . $tdclass . '">';

      print '<p><a href="' . $prodlink . '" title="' . $prodname . '">';
      print $prodname . '</a></p>' . $eol;

      if (!(empty($proddesc))) {print '<p>' . $proddesc . '</p>' . $eol;}

      $this->globals('ecom.prod_proddisp',$prod);
      $this->globals('ecom.prod_priceinfo',$prod['khxc.priceinfo']);
           
      $this->include_file($app,'pricedisp.php');

      if ($add_ok) {

            $this->include_namespace($app,'prodshowoptlite',array('form' => $formid . '--' . $prodid, 'showquan' => 0, 'headfoot' => 0));

      } // End of if statement.

      print '</td>' . $eol . $eol;

      // +--
      // | Close the table row.
      // +--

      //print '</tr>' . $eol . $eol;

if ($counter == 2) {

      // +--
      // | Close the table row.
      // +--

      print '</tr>' . $eol . $eol;

// +--
// | Print a table row opener.
// +--

      print '<tr class="' . $trclass . '">' . $eol . $eol;

$counter = 0;
}

} // End of foreach statement.

// +--
// | Print the table closure.
// +--

print '</table>' . $eol . $eol;

// +--
// | Print the form closure.
// +--

$this->xhtml_quickform_footer($formid,'Add To Purchase List',1);

// +--
// | Print navigation links if we have any.
// +--

if (!(empty($navarray))) {

     $this->include_file($app,'prodnav.php');

} // End of if statement.


// } // End of if statement.

?>

I realise that as the code is part of something else it may be of limited use to other people but, hopefully, the structure will be of use to others trying to output a foreach display in a multi-column format.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.