Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/125621-solved-dynamic-drop-down-box/
Share on other sites

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...

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)) {
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.