UncleSteve Posted October 7, 2006 Posted October 7, 2006 I'm stuck! :( Can anyone advise how I can change the display order of the page please? I want the categories displayed in alphabetical order, just like the products. Can anyone advise changes to the code please? Thanks in advance :) <?php /* $Id: all_products.php,v 3.0 2004/02/21 by Ingo ([email protected]) osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2004 osCommerce Released under the GNU General Public License */ require('includes/application_top.php'); include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ALL_PRODUCTS); $breadcrumb->add(HEADING_TITLE, tep_href_link(FILENAME_ALL_PRODUCTS, '', 'NONSSL')); ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <?php // BOF: WebMakers.com Changed: Header Tag Controller v1.0 // Replaced by header_tags.php if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) { require(DIR_WS_INCLUDES . 'header_tags.php'); } else { ?> <title><?php echo HEADING_TITLE; ?> :: <?php echo TITLE; ?></title> <?php } // EOF: WebMakers.com Changed: Header Tag Controller v1.0 ?> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <style type="text/css" media="screen"> <!-- .catentry {font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; color: #3E5E89; } h2 {font-family: Verdana, Arial, sans-serif; font-size: 20px; font-weight: bold; } h1, h2{margin-bottom:0px; margin-top:0px; line-height: 1em;} --> </style> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <!-- body //--> <table border="0" style="border: 1px solid #8200fe" width="100%" cellspacing="3" cellpadding="3"> <tr> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2"> <!-- left_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?> <!-- left_navigation_eof //--> </table></td> <!-- body_text //--> <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td><h2><font face="Arial"><?php echo HEADING_TITLE; ?></font></h2></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <tr> <td><table width="100%" cellspacing="0" cellpadding=0" border="0"> <?php $language_code = (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) ? $HTTP_GET_VARS['language'] : DEFAULT_LANGUAGE; $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id)"); $inc_cat = array(); while ($included_categories = tep_db_fetch_array($included_categories_query)) { $inc_cat[] = array ( 'id' => $included_categories['categories_id'], 'parent' => $included_categories['parent_id'], 'name' => $included_categories['categories_name']); } $cat_info = array(); for ($i=0; $i<sizeof($inc_cat); $i++) $cat_info[$inc_cat[$i]['id']] = array ( 'parent'=> $inc_cat[$i]['parent'], 'name' => $inc_cat[$i]['name'], 'path' => $inc_cat[$i]['id'], 'link' => '' ); for ($i=0; $i<sizeof($inc_cat); $i++) { $cat_id = $inc_cat[$i]['id']; while ($cat_info[$cat_id]['parent'] != 0){ $cat_info[$inc_cat[$i]['id']]['path'] = $cat_info[$cat_id]['parent'] . '_' . $cat_info[$inc_cat[$i]['id']]['path']; $cat_id = $cat_info[$cat_id]['parent']; } $link_array = split('_', $cat_info[$inc_cat[$i]['id']] ['path']); for ($j=0; $j<sizeof($link_array); $j++) { $cat_info[$inc_cat[$i]['id']]['link'] .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cat_info[$link_array[$j]]['path']) . '"><nobr>' . $cat_info[$link_array[$j]]['name'] . '</nobr></a> - '; } } $products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) ORDER BY pc.categories_id, pd.products_name"); while($products = tep_db_fetch_array($products_query)) { echo " <tr>\n" . ' <td width="33%" class="pageheading"><span class="catentry">' . (($memory == $products['categories_id'])? '': $cat_info[$products['categories_id']]['link']) . "</span></td>\n" . ' <td class="pageheading"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'] . (($language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $language_code))) . '"><span class="catentry">' . $products['products_name'] . "</span></a></td>\n" . " </tr>\n"; $memory = $products['categories_id']; } ?> </table></td> </tr> <tr> <td align="right" class="main"><br><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td> </tr> </table></td> <!-- body_text_eof //--> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2"> <!-- right_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_right.php'); ?> <!-- right_navigation_eof //--> </table></td> </tr> </table> <!-- body_eof //--> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> <!-- You are not the only one, John! --> ____________________________________________________________________ ____________________________________________________________________
ComicWisdom Posted October 7, 2006 Posted October 7, 2006 You don't need to change the code. Go to admin/catalog where you created the categories. Select a category hit the edit button. Fill in the sort order field the way you want them to appear in the menu. The lower the number the higher they are. Just between us, remember there are only 10 kinds of people in the world; those who understand binary and those who don't!! Remember, learning is a "do-it-yourself" experience; although, not necessarily a "do-it-BY-yourself" experience. The quickest way to learn is to forget to BACKUP!
squeekit Posted October 7, 2006 Posted October 7, 2006 i believe CosmicWisdom is right (again :D ).. if you clear each sort order feild for each category - i think alph order is default...
UncleSteve Posted October 8, 2006 Author Posted October 8, 2006 Hi Guy's, Thanks for the replies :) , however as previously posted I want the categories displayed in alphabetical order. The contents are already alpha sorted. Presently the categories are in the following order cbe Modular Ladders Pumps Sterling Seat Swivels Fiamma Steadies Ventilation Accessories Wheels Furniture Awnings Bathroom Not exactly alphabetical order :( Any ideas please on alpha sorting the categories? ____________________________________________________________________ ____________________________________________________________________
pyramids Posted October 8, 2006 Posted October 8, 2006 Change this: $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id)"); to: $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id) ORDER BY cd.categories_name");
UncleSteve Posted October 8, 2006 Author Posted October 8, 2006 Change this: $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id)"); to: $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id) ORDER BY cd.categories_name"); Hi Jeff, Thanks for the input :) I've run with your new code, but I still have the same category order :( Do you have any clues as to why it may not be working correctly? ____________________________________________________________________ ____________________________________________________________________
Guest Posted October 8, 2006 Posted October 8, 2006 Hi Uncle Steve I have all my category sort boxes set to 0 & it has automatically sorted them alphabetically for me. Sorry if you've tried this already jetbaby :)
UncleSteve Posted October 9, 2006 Author Posted October 9, 2006 Hi jetbaby, Thanks for your post. I've just checked mine and they're all set to 0. I have found that if you remove the 0, then save, it then defaults back to 0 Something which may be relivant is that the categories are in the order that I entered them on to the system. Uncle Steve ____________________________________________________________________ ____________________________________________________________________
pyramids Posted October 9, 2006 Posted October 9, 2006 try this: find: $products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) ORDER BY pc.categories_id, pd.products_name"); Change to: $products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id, cd.categories_name FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) AND pc.categories_id = cd.categories_id ORDER BY cd.categories_name, pd.products_name");
UncleSteve Posted October 9, 2006 Author Posted October 9, 2006 try this: find: $products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) ORDER BY pc.categories_id, pd.products_name"); Change to: $products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id, cd.categories_name FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) AND pc.categories_id = cd.categories_id ORDER BY cd.categories_name, pd.products_name"); Thanks Jeff, we now have a result! :D Now this is interesting ;) I now have the categories in alphabetical order :D But.... its got confused over sub categories :blink: The main or top (parent) layer of categories are in alpha order, but a sub-category (child) like Snap-Off, which is under Cab equipment, is shown as Cab Equipment - Snap-Off and then listed in the 'S' section, which looks a little odd when the line starts off with Cab. Perhaps it would look better without the parent category before the child? Something else I've noticed. I have an empty category listed in the categories box, but not in the 'All products list'. Its obviously clever enough to leave out any empty categories. ____________________________________________________________________ ____________________________________________________________________
UncleSteve Posted October 9, 2006 Author Posted October 9, 2006 Been playing with this for a while and made some improvements to the layout. Just wondering about reversing the parent child order. So that the child (if one present) is listed before the parent, then the alpha listing would look right. Can anyone help on this please? This seems to be the code for the parent child listings for ($i=0; $i<sizeof($inc_cat); $i++) { $cat_id = $inc_cat[$i]['id']; while ($cat_info[$cat_id]['parent'] != 0){ $cat_info[$inc_cat[$i]['id']]['path'] = $cat_info[$cat_id]['parent'] . '_' . $cat_info[$inc_cat[$i]['id']]['path']; $cat_id = $cat_info[$cat_id]['parent']; } $link_array = split('_', $cat_info[$inc_cat[$i]['id']] ['path']); for ($j=0; $j<sizeof($link_array); $j++) { $cat_info[$inc_cat[$i]['id']]['link'] .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cat_info[$link_array[$j]]['path']) . '">' . $cat_info[$link_array[$j]]['name'] . '</a> -<BR> '; After the parent or child has been listed, there is a hyphen ( - ) which I've added a <BR> to, thus giving a line break between the products of two categories. But you do need to add valign="bottom" to the product cell, otherwise the cell dosn't look right. I was wondering if its possible to only display the hyphen if a child category was listed with the parent (vice versa if they were reversed)? Any ideas please? ____________________________________________________________________ ____________________________________________________________________
Recommended Posts
Archived
This topic is now archived and is closed to further replies.