Guest Posted April 29, 2006 Posted April 29, 2006 Hi How do I change a report so that I can click on the column header and sort by that. I have a table that is made up like this: <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="formAreaTitle">ID</td> <td class="formAreaTitle">Barcode</td> <td class="formAreaTitle"><?php echo TABLE_HEADING_PRODUCTS; ?></td> <td class="formAreaTitle"><?php echo TABLE_HEADING_QUANTITY; ?></td> <td class="formAreaTitle" align="right"><?php echo TABLE_HEADING_PRICE; ?> </td> </tr> <tr> <td colspan="6"><hr></td> </tr> <?php $products_query_raw = "select p.products_id, pd.products_name, p.products_quantity, p.products_barcode, p.products_price, l.name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_LANGUAGES . " l where p.products_id = pd.products_id and p.products_id = pd.products_id and l.languages_id = pd.language_id and pd.language_id = '" . (int)$languages_id . "' order by pd.products_name ASC"; $products_query = tep_db_query($products_query_raw); while ($products = tep_db_fetch_array($products_query)) { $products_id = $products['products_id']; // check for product or attributes below reorder level $products_stock_query=tep_db_query("SELECT products_stock_attributes, products_stock_quantity FROM " . TABLE_PRODUCTS_STOCK . " WHERE products_id=" . $products['products_id'] ." AND products_stock_quantity < '" . STOCK_REORDER_LEVEL ."' ORDER BY products_stock_attributes"); $products_stock_rows=tep_db_num_rows($products_stock_query); if (($products['products_quantity'] < STOCK_REORDER_LEVEL) || ($products_stock_rows > 0)) { $products_quantity=($products_stock_rows > 0) ? ' ' : $products['products_quantity']; $products_price=($products_stock_rows > 0) ? ' ' : $currencies->format($products['products_price']); ?> <tr class="tableRow"> <td class="dataTableContent"><?php echo $products_id; ?></td> <td class="dataTableContent"><?php echo $products['products_barcode']; ?></td> <td class="formAreaTitle"><?php echo '<a href="' . tep_href_link(FILENAME_STOCK, 'product_id=' . $products['products_id']) . '">' . $products['products_name'] . '</a>'; ?></td> <td class="dataTableContent"><?php echo $products_quantity; ?></td> <td class="dataTableContent" align="right"><?php echo $products_price; ?> </td> </tr> <?php ///////////////// Add Attributes if ($products_stock_rows > 0) { $products_options_name_query = tep_db_query("SELECT distinct popt.products_options_id, popt.products_options_name FROM " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib WHERE patrib.products_id='" . $products['products_id'] . "' AND patrib.options_id = popt.products_options_id AND popt.products_options_track_stock = '1' AND popt.language_id = '" . (int)$languages_id . "' ORDER BY popt.products_options_id"); ?> <tr class="dataTableRow"> <td colspan="3" class="main"> <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="dataTableRow"> <?php // build headng line with option names while ($products_options_name = tep_db_fetch_array($products_options_name_query)) { echo " <td class=\"main\">" . $products_options_name['products_options_name'] . "</td>\n"; } ?> </tr> <?php // buld array of attributes price delta $attributes_price = array(); $products_attributes_query = tep_db_query("SELECT pa.options_id, pa.options_values_id, pa.options_values_price, pa.price_prefix FROM " . TABLE_PRODUCTS_ATTRIBUTES . " pa WHERE pa.products_id = '" . $products['products_id'] . "'"); while ($products_attributes_values = tep_db_fetch_array($products_attributes_query)) { $option_price = $products_attributes_values['options_values_price']; if ($products_attributes_values['price_prefix'] == "-") $option_price= -1*$option_price; $attributes_price[$products_attributes_values['options_id']][$products_attributes_values['options_values_id']] = $option_price; } // now display the attribute value names, table the html for quantity & price to get everything // to line up right $quantity_html_table=" <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">\n"; $quantity_html_table.=" <tr class=\"dataTableRow\"><td class=\"main\" colspan=\"" . sizeof($products_options_array) . "\"> </td></tr>\n"; $price_html_table=" <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">\n"; $price_html_table.=" <tr class=\"dataTableRow\"><td class=\"main\" colspan=\"" . sizeof($products_options_array) . "\"> </td></tr>\n"; while($products_stock_values=tep_db_fetch_array($products_stock_query)) { $attributes=explode(",",$products_stock_values['products_stock_attributes']); echo " <tr class=\"dataTableRowSelected\">\n"; $quantity_html_table.=" <tr class=\"dataTableRowSelected\">\n"; $price_html_table.=" <tr class=\"dataTableRowSelected\">\n"; $total_price=$products['products_price']; foreach($attributes as $attribute) { $attr=explode("-",$attribute); echo " <td class=smalltext>".tep_values_name($attr[1])."</td>\n"; $total_price+=$attributes_price[$attr[0]][$attr[1]]; } echo " </tr>\n"; $quantity_html_table.=" <td class=smalltext>" . $products_stock_values['products_stock_quantity'] . "</td>\n"; $quantity_html_table.=" </tr>\n"; $price_html_table.=" <td align=\"right\" class=smalltext>" . $total_price . " </td>\n"; $price_html_table.=" </tr>\n"; } echo " </table>\n"; echo " </td>\n"; $quantity_html_table.=" </table>\n"; $price_html_table.=" </table>\n"; echo " <td class=smalltext>" . $quantity_html_table . "</td>\n"; echo " <td>" . $price_html_table . "</td>\n"; echo " </tr>\n"; } } ////////////////////////// End Attributes } ?> <tr> <td colspan="3"><?php echo tep_draw_separator(); ?></td> </tr> </table></td> </tr> </table> I would like to ideally be able to easily sort by barcode or product name. Is this an easy job? Thanks W
Recommended Posts
Archived
This topic is now archived and is closed to further replies.