Jump to content

Recommended Posts

hi,

i've categories and sub categories link on left colum like this

 

*computer

    * keboard

    * mouse

    * keyboard

*calculator

    * M776

    * M345

*watch

 

here are computer, calculator and watches are main category.

and keyboard , mouse . M776...etc are sub categories of thier related category.

i need to show of fist sub-category data when i click on its main category.

example:

 

  if i click on "computer"(main-category) then it must show the data of "keboard"(sub-category)

  if i click on "calculator"(main-category) then it must show the data of "M776"(sub-category)

etc

any one know how to do that?

my code is listed below:

<style type="text/css">

<!--

body {

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

-->

 

 

</style>

<table cellpadding="0" cellspacing="0" width="100%">

<tr>

<td style="background:url(images/catagories-bg.jpg); background-repeat:repeat-x; background-color:#F8F8F8;">

   

   

<?php

/*

  $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 

  osCommerce, Open Source E-Commerce Solutions

  http://www.oscommerce.com

 

  Copyright © 2003 osCommerce

 

  Released under the GNU General Public License

*/

  //$firsts = "  <img src='images/right-arrow.jpg' width='3' height='5' />  ";

// $seconds= "<br><img src='images/categories-seperator.jpg' width='168' height='1' />";

 

 

  function tep_show_category($counter) {

    global $tree, $categories_string, $cPath_array;

 

    for ($i=0; $i<$tree[$counter]['level']; $i++) {

      $categories_string .= "  ";

    }

 

    $categories_string .= '<a href="';

 

    if ($tree[$counter]['parent'] == 0) {

      $cPath_new = 'cPath=' . $counter;

    } else {

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

    }

 

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

 

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {

      $categories_string .= '<b>';

    }

 

// display category name

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

 

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {

      $categories_string .= '</b>';

    }

 

    if (tep_has_category_subcategories($counter)) {

      $categories_string .= '';

    }

 

    $categories_string .= '</a>';

 

echo $counter."->".$tree[$counter]['parent'].$cPath_new."<br>";

 

    if (SHOW_COUNTS == 'true') {

      $products_in_category = tep_count_products_in_category($counter);

      if ($products_in_category > 0) {

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

      }

    }

 

    $categories_string .= '';

 

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

      tep_show_category($tree[$counter]['next_id']);

    }

  }

?>

<!-- categories //-->

 

 

<?php

// $info_box_contents = array();

//  $info_box_contents[] = array('text' => " ".BOX_HEADING_CATEGORIES.

                                        // " <img src='images/right-arrow.jpg' width='3' height='5' />");

/*<div class="divarea" > <img style="border-style:none;" src="images/right-arrow.jpg"/> '.$categories['categories_name'].'</div><img style="border-style:none;" src="images/categories-seperator.jpg"/> */

 

// new infoBoxHeading($info_box_contents, false, false);

// echo '<div style="height:8px; background-color:#1C75BD; margin:0px"></div> ';

  $categories_string = '';

  $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 = 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))  {

 

  /*$catshow ='<table cellpadding="0" cellspacing="0" border="0">

    <tr height="25"><td class="fontofcat" valign="middle" onmousemove="mover"> <img style="border-style:none;" src="images/right-arrow.jpg"/> '.$categories['categories_name'].'</td></tr>

    <tr><td><img style="border-style:none;" src="images/categories-seperator.jpg"/></td></tr>

</table>';*/

   

    $tree[$categories['categories_id']] = array('name'    => '<div class="divarea" > <img style="border-style:none;" src="images/right-arrow.jpg"/> '.$categories['categories_name'].'</div><img style="border-style:none;" src="images/categories-seperator.jpg"/>',

                                                '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'];

    }

  }

 

  //------------------------for sub catagories

  if (tep_not_null($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' => '<br><br>    '.$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;

      }

    }

  }

  tep_show_category($first_element);

 

  $info_box_contents = array();

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

 

  new infoBox($info_box_contents);

?>

    </td>

  </tr>

</table>           

<!-- categories_eof //-->

 

Try this PHP code for menu

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

 

<style type="text/css">

<!--

.menutd

{

font-family: Verdana;

font-size: 11px;

color:#000000;

background-color:#FFFFFF;

cursor:pointer;

}

.menumainbg

{

background-color:#ECE9D8;

}

.menuhead

{

font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:10px;

font-weight:bold;

height:20px;

cursor:pointer;

padding-top:5px;

}

.submenuhead

{

font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:10px;

font-weight:bold;

height:20px;

cursor:pointer;

}

.menutr

{

font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:10px;

font-weight:none;

background-color:#FFFFFF;

}

.menutr_over

{

font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:10px;

font-weight:none;

background-color:#E3E9F1;

cursor:pointer;

}

-->

</style>

<script language="javascript">

function Toggle(id,len)

{

var obj=document.getElementById("adminmgmt"+id);

var visible=(obj.style.display != "none");

if (visible)

obj.style.display="none";

else

obj.style.display="block";

}

</script>

</head>

 

<body>

<table width="150" border="0" cellspacing="0" cellpadding="0" align="left">

  <tr>

    <td>

<table width="100%" border="0" cellspacing="1" cellpadding="2">

<?php

$adm_menu = array (1 => "Heading 1", "Heading 2", "Heading 2");

$adm_sub_menu =

array

(

1 =>

array(

1 => array("Google", "http://www.google.com"), array("Yahoo", "http://www.yahoo.com"), array("Rediff", "http://www.rediff.com")),

array(

1 => array("Orkut", "http://www.orkut.com"), array("Times", "http://www.indiatimes.com")),

array(

1 => array("ABC", "http://www.abc.com"))

);

 

for($mnu1=1;$mnu1<=count($adm_menu);$mnu1++)

{

?>

  <tr>

<td align="left" valign="top" class="menumainbg">

<div onclick="javascript: Toggle(<?=$mnu1?>,<?=count($adm_menu)?>);" class="menuhead"><?=$adm_menu[$mnu1]?><?php if (count($adm_sub_menu[$mnu1]) > 0){?>   »<?php } ?></div>

<div style="display:none;" id="adminmgmt<?=$mnu1?>">

<table width="100%" border="0" cellspacing="1" cellpadding="5">

<?php

for($mnu2=1;$mnu2<=count($adm_sub_menu[$mnu1]);$mnu2++)

{

?>

  <tr>

<td class="menutr" onclick="javascript: window.location='<?=$adm_sub_menu[$mnu1][$mnu2][1]?>';" onmouseover="this.className='menutr_over';" onmouseout="this.className='menutr';"><?=$adm_sub_menu[$mnu1][$mnu2][0]?></td>

  </tr>

<?php

}

?>

</table>

</div>

</td>

  </tr>

<?php

}

?>

</table>

</td>

  </tr>

</table>

</body>

</html>

 

 

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.