Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with Drop Down Nav


Guest

Recommended Posts

Posted

Hey hey everybody!

 

I think I posted this in the wrong forum last time, so here we go again...

 

I want to start off by saying that I love OSC and I'm having a blast with it. Thanks for the awesome product!

 

Right now I'm trying to construct a drop down category tree (example found here).

 

I'm running the new MS2 and have come up with the following code to output the top level of categories:

 

query string:

  $categories_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 = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

 

code:

// Display a dropdown

$category_name_array = array();

   $category_name_array[] = array('id' => '', 

          'text' => PULL_DOWN_DEFAULT);



while ($categories = tep_db_fetch_array($categories_query)) {

  $categories_name = ((strlen($categories['categories_name']) > 20) ? substr($categories['categories_name'], 0, 20) . '..' : $categories['categories_name']);

  $category_name_array[] = array('id' => $categories['categories_id'],

             'text' => $categories_name);

}



$info_box_contents = array();

$info_box_contents[] = array('form' => tep_draw_form('drop_down_nav', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),

        'text' => tep_draw_pull_down_menu('cPath', $category_name_array, (isset($HTTP_GET_VARS['cPath']) ? $HTTP_GET_VARS['cPath'] : ''), 'onChange="this.form.submit();" size="1" style"width: 100%"') . tep_hide_session_id());



new infoBox($info_box_contents);

 

Now I'm looking for a way to output sub categories as well so I came up with this:

 

code (w/sub_categories):

// Display a dropdown

$category_name_array = array();

   $category_name_array[] = array('id' => '', 

          'text' => PULL_DOWN_DEFAULT);



while ($categories = tep_db_fetch_array($categories_query)) {

  $categories_name = ((strlen($categories['categories_name']) > 20) ? substr($categories['categories_name'], 0, 20) . '..' : $categories['categories_name']);

  $category_name_array[] = array('id' => $categories['categories_id'],

             'text' => $categories_name);

  if (isset($categories['parent_id'])) {

    $sub_categories_query = tep_db_query("select sc.categories_id, scd.categories_name, sc.parent_id from " . TABLE_CATEGORIES . " sc, " . TABLE_CATEGORIES_DESCRIPTION . " scd where sc.parent_id = '" . $categories['categories_id'] . "' and sc.categories_id = scd.categories_id and scd.language_id='" . (int)$languages_id ."' order by sort_order, scd.categories_name");

    while ($sub_categories = tep_db_fetch_array($sub_categories_query)) {

      $sub_categories_name = ((strlen($sub_categories['categories_name']) > 20 ? substr($sub_categories['categories_name'], 0, 20) . '..' : $sub_categories['categories_name']);

   $category_name_array[] = array('id' => $sub_categories['categories_id'],

             'text' => $sub_categories_name);

 }

  }

}



$info_box_contents = array();

$info_box_contents[] = array('form' => tep_draw_form('drop_down_nav', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),

        'text' => tep_draw_pull_down_menu('cPath', $category_name_array, (isset($HTTP_GET_VARS['cPath']) ? $HTTP_GET_VARS['cPath'] : ''), 'onChange="this.form.submit();" size="1" style"width: 100%"') . tep_hide_session_id());



new infoBox($info_box_contents);

 

That doesn't work (like the infobox doesn't even appear on the page or in the code), and I don't have enough programing experience to figure out why (I'm fresh out of high school, ok? :D ). Can you please help? Thanks in advance!

Posted

Ive sorted my categories dropdown problem now!

 

But thanks anyway!

 

-Matt

Posted

Also, your mod quite set the cPath correctly. It just sets it to the category id. But that screws up the breadcrumb nav system when you go to a category that has a parent category. I would like to tweak the mod to be able to set the cPath=(parent_id)_(category_id) because that is truly how the original non-drop-down category system worked.

Posted
Also, your mod quite set the cPath correctly. It just sets it to the category id. But that screws up the breadcrumb nav system when you go to a category that has a parent category. I would like to tweak the mod to be able to set the cPath=(parent_id)_(category_id) because that is truly how the original non-drop-down category system worked.

 

That's supposed to say didn't quite set the cPath correctly. Sorry...

Posted

Is this the mod from the contributions area, cause that is not my mod!

 

Also r u really straight from high school, cause your knowledge seems quite advanced!!!

 

-Matt

Posted
Is this the mod from the contributions area, cause that is not my mod!

 

Also r u really straight from high school, cause your knowledge seems quite advanced!!!

 

-Matt

Oh...I thought that it was your mod... :oops: :D

 

Yeah...I just graduated in June from good 'ol gresham hi skool :wink: in Oregon (man they sucked at giving quality computer programming classes). Actually, I've taken some classes at the local community college this last year as well (but I had to pay :cry: ). Thanks for the complement!

Posted
Just a bit of advice though I saw that you posted the same message here aswell:

 

http://www.oscommerce.com/forums/viewtopic.php?p=201251

 

This is called cross-posting and is against forum rules, so id recommend you didnt do it again.

 

-Matt

As you can see, I changed my post, so it's not the exact same post. :D

 

I'm new to the forum and thought that it would get a response there but since it didn't and you can't delete your posts or threads I thought that I'd just repost it in here. Thanks for the heads up. I won't do it again...

 

Does anyone have an idea of how to change the color or add spaces inbetween parent categories using the tep_get_categories function or am I going to have to write another function?

Posted

I wasnt critising I was just giving advice as your new to the forum, it saves a forum moderator having a go!

 

-Matt

Archived

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

×
×
  • Create New...