wilson210484 Posted September 24, 2008 Share Posted September 24, 2008 Hi im using oscommerce for my site i moded the manufacturers drop down box to filter one more time by using a simple switch statement only problem is my switch statement is getting longer and longer as it car makes and models so i want to use the path code IE http://partsforallcars.com/spares/index.php?dPath=22_94. here is the code i have been using Page one <?php /* $Id: manufacturers_list.php 6137 2005-05-10 12:59:09Z jim $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ $manufacturers_list_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '22' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by cd.categories_name"); if ($number_of_rows = tep_db_num_rows($manufacturers_list_query)) { ?> <!-- manufacturers //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_MANUFACTURERS_LIST); new infoBoxHeading($info_box_contents, false, false); // Display a drop-down $manufacturers_array = array(); $manufacturers_array[] = array('id' => '', 'text' => PULL_DOWN_DEFAULT); } while ($manufacturers = tep_db_fetch_array($manufacturers_list_query)) { $manufacturers_name = ((strlen($manufacturers['categories_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['categories_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['categories_name']); $manufacturers_array[] = array('id' => $manufacturers['parent_id']. '_'. $manufacturers['categories_id'], 'text' => $manufacturers_name); } $info_box_contents = array(); $info_box_contents[] = array('form' => tep_draw_form('categories', tep_href_link('partsarea.php', '', 'NONSSL', false), 'get'), 'text' => tep_draw_pull_down_menu('dPath',$manufacturers_array, (isset($HTTP_GET_VARS['categories_id']) ? $HTTP_GET_VARS['categories_id'] : ''), 'onChange="this.form.submit();" size="' . MAX_MANUFACTURERS_LIST . '" style="width: 180"') . tep_hide_session_id()); new infoBox($info_box_contents); if (file_exists('includes/manufacturer_model_list.php')) require('includes/manufacturer_model_list.php'); if (file_exists('spares/includes/manufacturer_model_list.php')) require('spares/includes/manufacturer_model_list.php'); //require('includes/manufacturer_model_list.php'); ?> <!-- manufacturers_eof //--> the next one is the include <?php switch($_GET[dPath]) { //ALFA case "22_91": $manufacturers_list_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '91' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."'order by cd.categories_name"); if ($number_of_rows = tep_db_num_rows($manufacturers_list_query)) { ?> <!-- manufacturers //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_MANUFACTURERS_MODEL_LIST); new infoBoxHeading($info_box_contents, false, false); // Display a drop-down $manufacturers_array = array(); $manufacturers_array[] = array(/*'id' => '', */'text' => PULL_DOWN_DEFAULT); } while ($manufacturers = tep_db_fetch_array($manufacturers_list_query)) { $manufacturers_name = ((strlen($manufacturers['categories_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['categories_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['categories_name']); $manufacturers_array[] = array('id' => $manufacturers['parent_id']. '_'. $manufacturers['categories_id'], 'text' => $manufacturers_name); } $info_box_contents = array(); $info_box_contents[] = array('form' => tep_draw_form('categories', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'), 'text' => tep_draw_pull_down_menu('cPath',$manufacturers_array, (isset($HTTP_GET_VARS['categories_id']) ? $HTTP_GET_VARS['categories_id'] : ''), 'onChange="this.form.submit();" size="' . MAX_MANUFACTURERS_LIST . '" style="width: 100%"') . tep_hide_session_id()); new infoBox($info_box_contents); ?> <!-- manufacturers_eof //--> <?php break; //AUDI case "22_37": $manufacturers_list_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '37' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."'order by cd.categories_name"); if ($number_of_rows = tep_db_num_rows($manufacturers_list_query)) { ?> <!-- manufacturers //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_MANUFACTURERS_MODEL_LIST); new infoBoxHeading($info_box_contents, false, false); // Display a drop-down $manufacturers_array = array(); $manufacturers_array[] = array(/*'id' => '', */'text' => PULL_DOWN_DEFAULT); } while ($manufacturers = tep_db_fetch_array($manufacturers_list_query)) { $manufacturers_name = ((strlen($manufacturers['categories_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['categories_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['categories_name']); $manufacturers_array[] = array('id' => $manufacturers['parent_id']. '_'. $manufacturers['categories_id'], 'text' => $manufacturers_name); } $info_box_contents = array(); $info_box_contents[] = array('form' => tep_draw_form('categories', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'), 'text' => tep_draw_pull_down_menu('cPath',$manufacturers_array, (isset($HTTP_GET_VARS['categories_id']) ? $HTTP_GET_VARS['categories_id'] : ''), 'onChange="this.form.submit();" size="' . MAX_MANUFACTURERS_LIST . '" style="width: 100%"') . tep_hide_session_id()); new infoBox($info_box_contents); ?> <!-- manufacturers_eof //--> <?php break; i have not put the full file as it goes on and on, is there a way to remove the switch statment and just have on option changing the call to the sql data base? Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/ Share on other sites More sharing options...
wilson210484 Posted September 24, 2008 Author Share Posted September 24, 2008 come on peps im desperate. ??? Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-649508 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Share Posted September 24, 2008 use if else statements instead Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-649518 Share on other sites More sharing options...
wilson210484 Posted September 24, 2008 Author Share Posted September 24, 2008 thought of that but thats just as long all i want to do is take the dpath out are put it in the sql data base call. Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-649521 Share on other sites More sharing options...
discomatt Posted September 24, 2008 Share Posted September 24, 2008 come on peps im desperate. ??? ... you're kidding, right? Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-649541 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Share Posted September 24, 2008 Turn the repetative code into a function and perform a function call on it when you need it, also if the case statements are in numerical order you could create a variable and have it incremented into appropriate amounts... Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-649546 Share on other sites More sharing options...
wilson210484 Posted September 25, 2008 Author Share Posted September 25, 2008 i sorted it just used a ' $_GET' statement. $pid = tep_db_prepare_input($_GET[dPath]); $manufacturers_list_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$pid ."' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."'order by cd.categories_name"); if ($number_of_rows = tep_db_num_rows($manufacturers_list_query)) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/#findComment-650322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.