Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with processing query results!?!?!


rotaour

Recommended Posts

I am trying to modify the Alternative Attributes Handling contrib and need some help fixing my code.

 

This contrib pulls all product options and attributes and displays them on the edit product page with easy to use checkboxes to set product options. Originally it dispalys each options attributes in one table in one row. In order to use the space on the page more efficiently and to make for less scrolling I'm trying to get the results into a columned table. I have working code but it has a looping problem. For instance I have 108 colors in the DB, when the page loads it lists each color 108 times instead of once. All else seems to be working properly, for example. if a color is linked to a specific product in the DB when that product page is loaded it pulls the right info.

 

Here the code in question:

       <!-- Attributes code start -->         
  <tr>
        <td>
           <table border="0" cellspacing="0" cellpadding="2">
<?php
   $rows = 0;
$columns=3;
   $options_query = tep_db_query("select products_options_id, products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . $languages_id . "' order by products_options_name");
   while ($options = tep_db_fetch_array($options_query)) {
     $values_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " p2p where pov.products_options_values_id = p2p.products_options_values_id and p2p.products_options_id = '" . $options['products_options_id'] . "' and pov.language_id = '" . $languages_id . "'");
     $header = false;
     while ($values = tep_db_fetch_array($values_query)) {
       $rows ++;
       if (!$header) {
         $header = true;
?>
<tr valign="top">
           <td><table border="0" cellpadding="0" cellspacing="0">
             <tr class="dataTableHeadingRow">
               <td class="dataTableHeadingContent"><?php echo $options['products_options_name']; ?></td><td class="dataTableHeadingContent" align="center">+/-</td><td class="dataTableHeadingContent" align="center">$Value</td>
             </tr>
<?php
       }
 
       $attributes = array();
       if (sizeof($HTTP_POST_VARS) > 0) {
         if ($HTTP_POST_VARS['option'][$rows]) {
           $attributes = array('products_attributes_id' => $HTTP_POST_VARS['option'][$rows],
                               'options_values_price' => $HTTP_POST_VARS['price'][$rows],
                               'price_prefix' => $HTTP_POST_VARS['prefix'][$rows]);
         }
       } else {
         $attributes_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $pInfo->products_id . "' and options_id = '" . $options['products_options_id'] . "' and options_values_id = '" . $values['products_options_values_id'] . "'");
         if (tep_db_num_rows($attributes_query) > 0) {
           $attributes = tep_db_fetch_array($attributes_query);
         }
       }

// CALCULATE ROWS & PROCESS QUERY RESULTS INTO COLUMNS/TABLES
$col=array(); 
$countrows=ceil(tep_db_num_rows($values_query)/$columns);
for ($x = 1; $x <= $columns; $x++) {
   for ($y =1; $y <= $countrows; $y++)
       $col[$x][$y] = tep_db_fetch_array($attributes_query);
}

// COLUMN WISE DYNAMIC TABLE
for ($y =1; $y <= $countrows; $y++) { 
   echo "<tr>"; 
   for ($x = 1; $x <= $columns; $x++) 
       if (isset($col[$x][$y][products_options_values_name])) {
 ?>
           <td class="dataTableContent"><?php echo tep_draw_checkbox_field('option[' . $rows . ']', $attributes['products_attributes_id'], $attributes['products_attributes_id']) . ' ' . $values['products_options_values_name']; ?> </td>
               <td class="dataTableContent"><?php echo tep_draw_input_field('prefix[' . $rows . ']', $attributes['price_prefix'], 'size="2"'); ?></td>
               <td class="dataTableContent"><?php echo tep_draw_input_field('price[' . $rows . ']', $attributes['options_values_price'], 'size="7"'); ?></td>
 <?php
       } else { 
           echo "<td>_blank</td>";
   echo "</tr>\n";
}
}

     }
     if ($header) {
?>
           </table></td>
<?php
     }
   }
?>
         </tr>
	 </table>
 </td>
</tr>

<!-- Attributes code stop -->

 

I've messed around with it a bit and cant seem to find the problem or remedy it. Any help, suggestions or comments would be greatly appreciated, thanks.

Matt Mika

Installed Contributions: Multi-Stores, QTPro, CCGV(trad), Batch Print, EasyPopulate, Simple Manual Order Entry, Encrypting Credit Card Via Mcrypt, UPSXML, Down for Maintenance, On The Fly GD Thumbs, SPPC, SPPC Hide, and various personal tweaks

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...