Help with Drop Down Nav
aedmonds <[email protected]> 24 Jul 2003 15:38:35 -0000
| Newsgroups | gmane.comp.web.oscommerce.devel |
|---|---|
| Message-ID | <8e28ef3844f0d1b98773428d240fe858@osCommerce-Forums> |
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=201251#201251
----------------------------------------------------------------
Hey hey everybody!
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 [url=http://www.utilityboardsupply.com/departments.asp?dept=1001]here[/url]).
I'm running the new MS2 and have come up with the following code to output the top level of categories:
query string:
[code] $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]
code:
[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);
[/code]
Now I'm looking for a way to output sub categories as well so I came up with this:
code (w/sub_categories):
[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);
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);
[/code]
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!