...

View Full Version : Newbie to PHP, Please help !



vanvoquan
11-24-2010, 09:21 AM
I have this code for my categories box of my shop. It shows the top level of the categories. When I click that categories, it will show the sub-categories of that categories. And when I click that sub-categories, will show the sub-categories of that sub-categories. Now I want it always show the top level categories and the sub-categories of that categories, I dont have to click or anything. Can somebody good at php help me out? Or point me to the right direction. Thank you million times.

<?php
function new_tep_show_category($boxId,&$cPath_array,&$tree,$counter)
{
global $cat_name; // CategoryBox Enhancement
for ($i=0; $i<$tree[$counter]['level']; $i++)

$categories_string = "&nbsp;&nbsp;";

// $cPath_new = 'cPath=' . $tree[$counter]['path']; // CategoryBox Enhancement
$categories_string .= '<b><a href="';


$cPath_new = 'cPath=' . $tree[$counter]['path'];

// $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; // CategoryBox Enhancement
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

if ($boxId == $_SESSION['infoBox'] && isset($cPath_array) && in_array($counter, $cPath_array))
{

// commented for CategoryBox Enhancement $categories_string .= '<b>' . $tree[$counter]['name'] . '</b>';
$categories_string .= '<b>';

// CategoryBox Enhancement
if ($cat_name == $tree[$counter]['name']) {
$categories_string .= '<span class="errorText">';
}
// CategoryBox Enhancement

$categories_string .= $tree[$counter]['name'];

// CategoryBox Enhancement
if ($cat_name == $tree[$counter]['name']) {
$categories_string .= '</span>';
}
// CategoryBox Enhancement

$categories_string .= '</b>';
}

else
{
// CategoryBox Enhancement
if ($cat_name == $tree[$counter]['name']) {
$categories_string .= '<b><span class="errorText">';
}
// CategoryBox Enhancement

$categories_string .= $tree[$counter]['name'];

// CategoryBox Enhancement
if ($cat_name == $tree[$counter]['name']) {
$categories_string .= '</span></b>';
}
// CategoryBox Enhancement
}

/* commented for CategoryBox Enhancement
if (tep_has_category_subcategories($counter))

$categories_string .= '-&gt;';
*/

$categories_string .= '</a>';

if (SHOW_COUNTS == 'true') {

$products_in_category = tep_count_products_in_category($counter);

if ($products_in_category > 0)

$categories_string .= '&nbsp;(' . $products_in_category . ')';

}

$categories_string .= '<br>';

if ($tree[$counter]['next_id'] != false)

$categories_string .= new_tep_show_category($boxId,$cPath_array,$tree,$tree[$counter]['next_id']);

return $categories_string;
}

function tep_categories_box($boxId,&$infoBox,$follow_cPath,&$cPath_array)
{
global $languages_id;

$info_box_contents = array();
$info_box_contents[] = array('text' => $infoBox['name']);

new infoBoxHeadingCategories($info_box_contents, true, false);

$tree = array();

$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 in (".implode(',',$infoBox['categories']).") and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {

$tree[$categories['categories_id']] = array(
'name' => $categories['categories_name'],
'parent' => $categories['parent_id'],
'level' => 0,
'path' => $categories['categories_id'],
'next_id' => false
);

if (isset($parent_id))
$tree[$parent_id]['next_id'] = $categories['categories_id'];

$parent_id = $categories['categories_id'];

if (!isset($first_element))
$first_element = $categories['categories_id'];

}

//------------------------
if ($follow_cPath) {

$new_path = '';

reset($cPath_array);

while (list($key, $value) = each($cPath_array)) {

unset($parent_id);
unset($first_id);

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

if (tep_db_num_rows($categories_query)) {

$new_path .= $value;

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

$tree[$row['categories_id']] = array(
'name' => $row['categories_name'],
'parent' => $row['parent_id'],
'level' => $key+1,
'path' => $new_path . '_' . $row['categories_id'],
'next_id' => false
);

if (isset($parent_id))

$tree[$parent_id]['next_id'] = $row['categories_id'];


$parent_id = $row['categories_id'];

if (!isset($first_id))

$first_id = $row['categories_id'];


$last_id = $row['categories_id'];

}

$tree[$last_id]['next_id'] = $tree[$value]['next_id'];

$tree[$value]['next_id'] = $first_id;

$new_path .= '_';

} else {

break;

}

}

}

$info_box_contents = array();
$info_box_contents[] = array('text' => new_tep_show_category($boxId,$cPath_array,$tree,$first_element));

new infoBox($info_box_contents);
}

?>
<!-- categories //-->
<?php

$_infoBox = array();

// define('TABLE_CATEGORIES_MORE','categories_more');

$categories_this_infobox_query = tep_db_query("select * from " . TABLE_CATEGORIES_MORE . " where enabled = 1");

while ($_categories = tep_db_fetch_array($categories_this_infobox_query))

$_infoBox[] = array(
'categories' => array(
$_categories['category1_id'],
$_categories['category2_id'],
$_categories['category3_id'],
$_categories['category4_id'],
$_categories['category5_id'],
$_categories['category6_id'],
$_categories['category7_id'],
$_categories['category8_id'],
$_categories['category9_id'],
$_categories['category10_id'],
$_categories['category11_id'],
$_categories['category12_id'],
$_categories['category13_id'],
$_categories['category14_id'],
$_categories['category15_id'],
$_categories['category16_id'],
$_categories['category17_id'],
$_categories['category18_id'],
$_categories['category19_id'],
$_categories['category20_id'],
$_categories['category21_id'],
$_categories['category22_id'],
$_categories['category23_id'],
$_categories['category24_id'],
$_categories['category25_id'],
),
'name' => $_categories['infobox_name'],
'enabled' => $_categories['enabled']
);

if (!tep_session_is_registered('infoBox')) {

tep_session_register('infoBox');

$infoBox = '0';

}

if (isset($_GET['infoBox']) && is_numeric($_GET['infoBox']))
$infoBox = $_GET['infoBox'];

for($i=0,$n=2 ; $i<$n; $i++) {

echo "<tr>\n<td>\n";

tep_categories_box(
$i,
$_infoBox[$i],
($infoBox == $i && tep_not_null($cPath)) ? true : false,
$cPath_array
);

echo "\n</td>\n</tr>\n";

}
?>
<!-- categories_eof //-->

vanvoquan
11-24-2010, 07:05 PM
Anybody?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum