News:

Looking for documentation? Take a look on our wiki

Main Menu

Table repeating in Browse_Table.

Started by smi4motion, March 27, 2012, 20:48:51 PM

Previous topic - Next topic

smi4motion

I have a (browse_table) template I have designed for virtuemart.  However the main table keeps repeating.  I am attaching the codes for review.  What I want is a table with 3 columns (L,C,R).  Then I want the virtuemart product table to be built inside the center cell of the main table.    So right now as the code sites, if the category has 6 products then the entire table is built 6 times instead of just once.  Please help ASAP.  Here is the code.


<table border="1" width="100%" bordercolor="#FF0000">
<tr>
<td>Left column</td>
<td>

<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); ?>

<?php echo $buttons_header // The PDF, Email and Print buttons ?>
<?php echo $browsepage_header // The heading, the category description ?>
<?php echo $parameter_form // The Parameter search form ?>
<?php echo $orderby_form // The sort-by, order-by form PLUS top page navigation ?>

<?php
$data =array(); // Holds the rows of products
$i = 1; $row = 0; // Counters

// Table header
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_DIAMETER');
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_NAME');
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_DESC_TITLE');
if( _SHOW_PRICES && $auth['show_prices'] ) {
   $tableheader[] = $VM_LANG->_('PHPSHOP_CART_PRICE');
}
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_THUMB_IMAGE');
if( _SHOW_PRICES && $auth['show_prices'] && USE_AS_CATALOGUE != '1' ) {
   $tableheader[] = $VM_LANG->_('PHPSHOP_CART_ACTION');
}

// Creates a new HTML_Table object that will help us
// to build a table holding all the products
$table =& new HTML_Table('width="100%"');

$table->addRow( $tableheader, 'class="sectiontableheader"', 'th', true );

foreach( $products as $product ) {
      
      foreach( $product as $attr => $val ) {
         // Using this we make all the variables available in the template
         // translated example: $this->set( 'product_name', $product_name );
         $this->set( $attr, $val );
      }
      
      $data[$row][] = $product['diameter'];
      
      $data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'.$product['product_name'].'</a>';
      $data[$row][] = $product['product_s_desc'];
      if( _SHOW_PRICES && $auth['show_prices'] ) {
         $data[$row][] = $product['product_price'];
      }
      $data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
                  . ps_product::image_tag( $product['product_thumb_image'] )
                  . '</a>';
      if( $product['has_addtocart'] ) {
         $data[$row][] = $product['form_addtocart'];
      }
      else {
         $data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
                     .   $product['product_details']
                     .   '</a>';
      }
      
      $row++;
      
}


// Loop through each row and build the table
foreach($data as $key => $value) {
   
   $table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
   $i = $i == 1 ? 2 : 1;
}
// Display the table
echo $table->toHtml();
?>
<br class="clr" /><br />
<?php
// Show Featured Products
if( $this->get_cfg( 'showFeatured', 1 )) {
    /* featuredproducts(random, no_of_products,category_based) no_of_products 0 = all else numeric amount
    edit featuredproduct.tpl.php to edit layout */
    echo $ps_product->featuredProducts(true,10,true);
} ?>
<?php echo $recent_products ?>
<?php echo $browsepage_footer ?>

</td>
<td>Right column</td>
</tr>
</table>

jenkinhill

Is this with VirtueMart 2? This is the VM2 forum section - that looks like the old 1.1 version?
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum