Solved

Issue PHP MySQL Dynamic multi level menu with javascript

Posted on 2010-11-28
30
874 Views
Last Modified: 2012-05-10
Hi Experts,
Novice, kindly bear with me! I am working on a category - multiple category menu, that is using PHP recursive function.

After intensive search, trial and error I found a perfect code snippet that suites my requirements very well except a small glitch. As per the original script the menu links are called from the category table field 'links'. Instead I want to call a field or pass an url parameter from another table (ie the product table) These tables are connected with a foreign id in the product table "prod_catid"

I want two things to be cleared:
1. The link should be from product table or it should land at 'product.php' and pass a url variable (prod_id) along.
2. Now the onclick event opens a new window, instead I want this to open in the same window.

The relevant part of the code is here

 
function getChild($id)
		{
			$menu = "";
			$str = "";
			$s = "select id,title,parentid,link from main_cat where parentid = '$id' ";
			$res = $this->select_row($s);
			$menu .= '<div id="'.$id.'" style="display:none; position:absolute;" onmouseover="javascript: return showId('.$id.');" onmouseout="javascript: return hideId('.$id.');">';
			$menu .= '<table border="0" cellspacing="0" cellpadding="0" style="border: 0px solid #FFFFFF;  border-collapse:collapse;">';
			for ($i=0;$i<count($res);$i++)
			{
				$cnt_of_child = $this->recordCount("select id from main_cat where parentid = '".$res[$i][id]."' ");
				if ($cnt_of_child > 0)
					$str = '&nbsp;&nbsp;&nbsp;<img src="images/more_arrowW.gif">';
				else
					$str = " ";
					
				
				$menu .= '<tr height="40"><td align="left"  class="aerial12" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #FFFFFF;" onmouseover="this.className=\'aerial12over\';return showId('.$res[$i][id].');" onmouseout="this.className=\'aerial12\';return hideId('.$res[$i][id].');" style="cursor:pointer;">';
				$menu .= '<div style="padding-left:10px;padding-right:5px; padding-top:5px; padding-bottom:5px; width:150px;"  onclick="javascript: return redirect(\''.$res[$i][link].'/\');">';

Open in new window


Appreciate any help.
0
Comment
Question by:jayseena
  • 17
  • 13
30 Comments
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34225775
This isn't the relevant part of the code.  You're not showing the functions 'showID', 'hideID', or 'redirect'.  There is nothing in this code that directly opens a window.

What you should look for is calls to 'window()', are a reference to 'target=' if it's opening another window.
0
 

Author Comment

by:jayseena
ID: 34225884
Sorry about that. My ignorance. Here is the full code.
<?php

	// PROJECT RELATED FUNCTIONS

	class PHP_fun 

	{

		function getConfig()

		{

			$this->DB_SERVER = 'localhost';

			$this->DB_USER = 'root';

			$this->DB_PASS = '';

			$this->DB_NAME = 'my_db';

		

		}

	

		function __construct()

		{

			$this->getConfig();

			$Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS);

			if (!$Conn)

				die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));

			$DB_select = mysql_select_db($this->DB_NAME, $Conn);

			if (!$DB_select)

				die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));

		}



		function select_row($sql)

		{

			//echo $sql . "<br />";

			if ($sql!="")

			{

				$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());

				if ($result)

				{

					while($row = mysql_fetch_array($result))

						$data[] = $row;

				}

				return $data;

			}

		}



		function recordCount($sql)

		{

			if ($sql!="")

			{

				$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());

				if ($result)

				{

					$cnt = mysql_num_rows($result);

					return $cnt;

				}

			}

		}



		function createProductUrl($url)

		{

			$url = trim($url);

			if ($url != "")

			{

				$url = trim(str_replace(" ","-",$url));

				//return $url.".html";

				return $url;

			}

		}

		

		function getChild($id)

		{

			$menu = "";

			$str = "";

			$s = "select id,title,parentid,link from ms_product where parentid = '$id' ";

			$res = $this->select_row($s);

			$menu .= '<div id="'.$id.'" style="display:none; position:absolute;" onmouseover="javascript: return showId('.$id.');" onmouseout="javascript: return hideId('.$id.');">';

			$menu .= '<table border="0" cellspacing="0" cellpadding="0" style="border: 0px solid #FFFFFF;  border-collapse:collapse;">';

			for ($i=0;$i<count($res);$i++)

			{

				$cnt_of_child = $this->recordCount("select id from ms_product where parentid = '".$res[$i][id]."' ");

				if ($cnt_of_child > 0)

					$str = '&nbsp;&nbsp;&nbsp;<img src="images/more_arrowW.gif">';

				else

					$str = " ";

					

				

				$menu .= '<tr height="30"><td align="left"  class="aerial12" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #FFFFFF;" onmouseover="this.className=\'aerial12over\';return showId('.$res[$i][id].');" onmouseout="this.className=\'aerial12\';return hideId('.$res[$i][id].');" style="cursor:pointer;">';

				$menu .= '<div style="padding-left:10px;padding-right:5px; width:150px;"  onclick="javascript: return redirect(\''.$res[$i][link].'/\');">';





				$menu .= $res[$i][title].$str;	

				$menu .= '</div>';

				$menu .= '</td><td align="left" valign="top">';					

				$menu .= $this->getChild($res[$i][id]);

				$menu .= '</td></tr>';					

			}

			$menu .= '</table>';

			$menu .= '</div>';		

			return $menu;

		}

		

		function getMenu($parentid)

		{

			$menu = "";

			$s = "select id,title,parentid,link from ms_product where parentid = '$parentid'  ";

			$res = $this->select_row($s);

			ob_start();

			?>

			<table border="0" cellspacing="0" cellpadding="0" align="center">

				<tr height="30">

					

		<?php

			for ($i=0;$i<count($res);$i++)

			{ ?>

					<td align="left" valign="middle" bgcolor="#FCBB2B">

				  

				  		<div align="center" onmouseover="javascript: return showId('<?=$res[$i][id]?>');" onmouseout="javascript: return hideId('<?=$res[$i][id]?>');" onclick="javascript: return redirect('<?=$res[$i][link]?>');" class="aerial12" ><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Products','','images/products_over.png',1)" style="text-decoration:none"><img src="images/products.png" alt="Products" name="Products" width="105" height="56" border="0" id="Products" /></div><?=$this->getChild($res[$i][id])?>				  </td>

				  <?php if ((count($res) - 1) > $i) {?>

					<?php } ?>

			<?php } ?>

					</table>

<?php

			$menu = ob_get_contents();

			ob_end_clean();

			return $menu;

		}

	}//class PHP_fun()

?>

Open in new window

0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34228120
I still do not see where 'redirect()' is defined.  Most likely the problem is in the javascript, not the PHP.
0
 

Author Comment

by:jayseena
ID: 34228488
At line 82 we have onclick="javascript: return redirect(\''.$res[$i][link].'/\');">';
I think this what gives me problem
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34229987
Yes, but where is 'redirect' defined?  It's part of the javascript running on the client browser, not part of this PHP.
0
 

Author Comment

by:jayseena
ID: 34230099
I am blank. This file is included in menu page
<?php
      include("functions.php");
      $db = new PHP_fun;
?>

The function is called on the page by <?=$db->getMenu(0);?> except that there is no external libraries

0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34230235
Look in that functions,php file and see if redirect() is defined there.  You're not showing all the code so it's only a guess at what the cause is.  But again, it's probably a call to 'window()' or a 'target=' clause.

On the client, 'view source' and find what 'redirect()' is doing.
0
 

Author Comment

by:jayseena
ID: 34230294
You're not showing all the code so it's only a guess at what the cause is

I copied the entire code above. The source of the code is down below:
http://www.phpclasses.org/package/5927-PHP-Display-an-hierarchic-menu-stored-in-a-MySQL-table.html#download
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34230439
No, you didn't copy the entire code.  From looking at your link what you seem to be interested in is in the menu.php file, where redirect() is defined with 'window.open(url)'.  If you want it to open in the current window instead of a separate window change that to 'location.href = url;'
0
 

Author Comment

by:jayseena
ID: 34230699
You are absolutely right. Extremely sorry that I overlooked it. I am able to solve that issue with your great support. May I ask your support on the next bit of trouble I am facing.  
viz.
I want to lead the menu link to the product.php page along with the 'product_id' url variable. Currently the link is from the category table field 'link'. The link should be from product table.
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34231085
Where are you getting your product_id's?  The only query I see is:

  $s = "select id,title,parentid,link from ms_product where parentid = '$id' ";

and from looking at the link you posted that is retrieving categories, not products.
0
 

Author Comment

by:jayseena
ID: 34231159
True. The product table is called in the menu.php. Not on functions.php (where the above code is from).
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34232152
You will just have to build the 'url' that you pass to 'redirect' so that it goes to the link you want it to go to.

If you want a more specific answer you're going to have to post some actual code.
0
 

Author Comment

by:jayseena
ID: 34236354
Hi,
Here is what I am trying to do.

Table Structure:
main_cat
id          title            parentid
1           Fruit                0
2           Apple              1
3           Red Apple       2

product_table

prod_id      cat_id     details
1                    1        Fruit Details
2                    2        Apple Details
3                    2        Another Apple Details
4                    3        Red Apple Details
5                    2        Another Apple Details  


Want to select all from category

$s = "select id,title,parentid,link from ms_product where parentid = '$id' ";

Open in new window


Works fine

Next, want to select both the tables to get the prod_id and pass it as a url param.

$s = "SELECT main_cat.*,  product.* FROM (product RIGHT JOIN main_cat ON main_cat.id=product.prod_catid) where parentid = '$id' ";

Open in new window


Problem here: I have the category name repeating as many times as the foreign ids in the product table
Tried  SELECT DISTINCT, but no use.

Additionally I want to point the menu link to something like
product.php?id=<?php echo $row_products['id']; ?>

Open in new window


I am trying to edit here

$menu .= '<div style="padding-left:10px;padding-right:5px; width:150px;"  onclick="javascript: return redirect(\''.$res[$i][link].'/\');">';

Open in new window


How can I edit this portion to reflect the path I am trying to achieve without a parse error!
(\''.$res[$i][link].'/\')

Open in new window

0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34244127
You say this statement works:

  $s = "select id,title,parentid,link from ms_product where parentid = '$id' ";

Notice that column named 'link' in that query.  That is where the link is coming from.

Then you have this query:

  $s = "SELECT main_cat.*,  product.* FROM (product RIGHT JOIN main_cat ON main_cat.id=product.prod_catid) where parentid = '$id' ";

I strongly discourage the use of '*' in any query. Just query what you need.

  $s = "SELECT prod_id from product where cat_id = (SELECT id from main_cat where parentid = $id";

And I assume the product table does not have a 'link' column, so you want to build it from the prod_id, which would be something like:

  $menu .= '<div style="padding-left:10px;padding-right:5px; width:150px;"  onclick="javascript: return redirect(\'http://my.domain.com/product_id.php?prod_id=' . $res[$i][prod_id] . '\');">';
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:jayseena
ID: 34245126
Thank you very much. That worked well. I am now left with the last silly problem of category name repeating as many times as the foreign ids in the product table
Tried  SELECT DISTINCT, but didn't work.

To explain a bit more: Again to the table

Table Structure:
main_cat
id          title            parentid
1           Fruit                0
2           Apple              1
3           Red Apple       2

product_table

prod_id      cat_id     details
1                    1        Fruit Details
2                    2        Apple Details
3                    2        Another Apple Details
4                    3        Red Apple Details
5                    2        Another Apple Details  

Menu appears as:
Fruit
Apple
Apple
Red Apple
Apple

How to avoid the Apple repetition?
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34245592
That's because you have multiple products per category. You can either query your categories separately, or list the products instead of the categories.

But after looking at the functions.php file I think I see what you're trying to do now.  Are you trying to create a multilevel drop-down menu similar to 'Category 1' on this page ?  --> http://www.nashikads.com/dynamic-menu/index.php

If that's the case then you would just have to modify the getChild() function so that it queries the product table instead of the category field, and apply what you've learned so far to get what you want.

So your getMenu() function queries the category table to get the categories, then within that function it calls the getChild() function to get all the products within that category, creating the drop-down menus for each category.
0
 

Author Comment

by:jayseena
ID: 34249254
Sorry for not responding fast. Was away from computer for the whole day today.
Yes, I am trying to achieve the same result as it shows in the link. I will give a try as you instructed and get back with the result.
Thanks for your support so far.
0
 

Author Comment

by:jayseena
ID: 34265109
After trying for so many hours for the past two days, I found this simply beyond my reach. As a last resort, I am coming back to you to see if you could help me sort this out for ever!!!

I am not able to make the query to select the distinct values. I tried distinct, group by etc. Tried joining the tables in different ways.....
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34266576
Show what you have so far for getmenu.php and functions.php
0
 

Author Comment

by:jayseena
ID: 34267481
Yes. I will just pass the entire files

DB Name - gab_data
Table - Category: SQL
CREATE TABLE IF NOT EXISTS `main_cat` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` text,
  `link` text CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
  `parentid` bigint(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  FULLTEXT KEY `pravin` (`title`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=21 ;

--
-- Dumping data for table `main_cat`
--

INSERT INTO `main_cat` (`id`, `title`, `link`, `parentid`) VALUES
(1, '---- ------', '', 0),
(2, 'Forceps', 'products.php', 1),
(3, 'Scissors', 'Null', 1),
(17, 'Needle Holders', 'Null', 1),
(18, 'Needle Holder Forceps', 'Null', 1),
(19, 'Category 1C', 'link', 18),
(20, 'Category 8', 'link', 3);

Open in new window


Table - product: SQL

CREATE TABLE IF NOT EXISTS `product` (
  `prod_id` int(11) NOT NULL AUTO_INCREMENT,
  `prod_catid` int(11) DEFAULT NULL,
  `prod_name` varchar(255) DEFAULT NULL,
  `prod_desc` mediumtext,
  `prod_type` int(1) DEFAULT NULL,
  `prod_image` varchar(300) DEFAULT NULL,
  `prod_refid` varchar(20) DEFAULT NULL,
  `prod_featured` int(1) DEFAULT NULL,
  `prod_featureimg` varchar(300) DEFAULT NULL,
  `prod_keywords` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`prod_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

--
-- Dumping data for table `product`
--

INSERT INTO `product` (`prod_id`, `prod_catid`, `prod_name`, `prod_desc`, `prod_type`, `prod_image`, `prod_refid`, `prod_featured`, `prod_featureimg`, `prod_keywords`) VALUES
(1, 1, 'Speculum2', '<p>New Product Descriptionsadsadas</p>', 1, '', '252522', 1, NULL, NULL),
(2, 2, 'Forceps', 'New Product Description', 0, 'Blue hills.jpg', '25252233', 0, 'Water lilies.jpg', NULL),
(3, 2, 'Scissors', 'asdsadsadsadsa', 1, 'a.jpg', '23423', 1, 'sadas.jpg', NULL),
(5, 5, 'Needle Holder Forceps', 'New details ', 0, '', '312223', 1, '', 'sample keywords for needle holder forceps'),
(12, 2, 'adsadsadsa', NULL, 1, 'Winter_1.jpg', '2342', 0, 'Winter.jpg', NULL),
(7, 2, 'New Forecps', '<p>Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno est&aacute;ndar de las industrias desde el a&ntilde;o 1500, cuando un</p>\r\n<p>impresor (N. del T. persona que se dedica a la imprenta) desconocido us&oacute; una galer&iacute;a de textos y los mezcl&oacute; de tal manera que logr&oacute; hacer un libro de textos especimen. No s&oacute;lo sobrevivi&oacute; 500 a&ntilde;os, sino que tambien ingres&oacute; como texto de relleno en documentos electr&oacute;nicos, quedando esencialmente igual al original. Fue popularizado en los 60s con la creaci&oacute;n de las hojas</p>\r\n<p>"Letraset", las cuales contenian pasajes de Lorem Ipsum, y m&aacute;s recientemente con software de autoedici&oacute;n, como por ejemplo Aldus PageMaker, el cual incluye versiones de Lorem Ipsum.</p>', 3, '7455paint_can.jpg', '234423423', 1, '7455paint_can.jpg', '<p>No keywords</p>'),
(11, 5, 'Sample', NULL, 3, '1_2.jpg', '324232342', 1, '1.jpg', NULL),
(10, 2, 'Forceps Premium', '<p>Suggested Dimensions:<br /> Product Image: (W)530px X (H)300 px or proportanally large.<br /> Featured Image: Any Square size. (Min 140 x 140 px)<br /> To edit images click here:</p>', 2, '1_1.jpg', '222', 1, '038_6666x5000.jpg', 'Forceps, Gynesol Forceps'),
(13, 2, 'Test', '<p>Test1</p>', 1, 'Test_1.jpg', '234423423', 1, 'Test.jpg', NULL),
(14, 2, 'Cusco', '<p>Cusco</p>', 1, 'Cusco_1.jpg', '2342', 1, 'Cusco.jpg', 'Cusco');

Open in new window


functions.php
<?php
// PROJECT RELATED FUNCTIONS
	class PHP_fun 
	{
		function getConfig()
		{
			$this->DB_SERVER = 'localhost';
			$this->DB_USER = 'root';
			$this->DB_PASS = '';
			$this->DB_NAME = 'gab_data';
		
		}
	
		function __construct()
		{
			$this->getConfig();
			$Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS);
			if (!$Conn)
				die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
			$DB_select = mysql_select_db($this->DB_NAME, $Conn);
			if (!$DB_select)
				die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
		}

		function select_row($sql)
		{
			//echo $sql . "<br />";
			if ($sql!="")
			{
				$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
				if ($result)
				{
					while($row = mysql_fetch_array($result))
						$data[] = $row;
				}
				return $data;
			}
		}

		function recordCount($sql)
		{
			if ($sql!="")
			{
				$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
				if ($result)
				{
					$cnt = mysql_num_rows($result);
					return $cnt;
				}
			}
		}

		function createProductUrl($url)
		{
			$url = trim($url);
			if ($url != "")
			{
				$url = trim(str_replace(" ","-",$url));
				//return $url.".html";
				return $url;
			}
		}
		
		function getChild($id)
		{
			$menu = "";
			$str = "";
			
			
			
			$s = "SELECT main_cat.*,  product.* FROM (product RIGHT JOIN main_cat ON main_cat.id=product.prod_catid) where parentid = '$id' ";
			$res = $this->select_row($s);
			$menu .= '<div id="'.$id.'" style="display:none; position:absolute;" onmouseover="javascript: return showId('.$id.');" onmouseout="javascript: return hideId('.$id.');">';
			$menu .= '<table border="0" cellspacing="0" cellpadding="0" style="border: 0px solid #FFFFFF;  border-collapse:collapse;">';
			for ($i=0;$i<count($res);$i++)
			{
				$cnt_of_child = $this->recordCount("select id from main_cat where parentid = '".$res[$i][id]."' ");
				if ($cnt_of_child > 0)
					$str = '&nbsp;&nbsp;&nbsp;<img src="images/more_arrowW.gif">';
				else
					$str = " ";
					
				
				$menu .= '<tr height="40"><td align="left"  class="aerial12" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #FFFFFF;" onmouseover="this.className=\'aerial12over\';return showId('.$res[$i][id].');" onmouseout="this.className=\'aerial12\';return hideId('.$res[$i][id].');" style="cursor:pointer;">';

				
				
				
			$menu .= '<div style="padding-left:10px;padding-right:5px; width:150px;"  onclick="javascript: return redirect(\'http://localhost/product_id.php?prod_id=' . $res[$i][prod_id] . '\');">';
				
				


				$menu .= $res[$i][title].$str;	
				$menu .= '</div>';
				$menu .= '</td><td align="left" valign="top">';					
				$menu .= $this->getChild($res[$i][id]);
				$menu .= '</td></tr>';					
			}
			$menu .= '</table>';
			$menu .= '</div>';		
			return $menu;
		}
		
		function getMenu($parentid)
		{
			$menu = "";
			$s = "select id,title,parentid,link from main_cat where parentid = '$parentid'";
			$res = $this->select_row($s);
			ob_start();
			?>
			<table border="0" cellspacing="0" cellpadding="0" align="center">
				<tr height="30">
					
		<?php
			for ($i=0;$i<count($res);$i++)
			{ ?>
					<td align="left" valign="middle" bgcolor="#FCBB2B">
				  
				  		<div align="center" onmouseover="javascript: return showId('<?=$res[$i][id]?>');" onmouseout="javascript: return hideId('<?=$res[$i][id]?>');"class="aerial12" ><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Products','','images/products_over.png',1)" style="text-decoration:none"><img src="images/products.png" alt="Products" name="Products" width="105" height="56" border="0" id="Products" /></div><?=$this->getChild($res[$i][id])?>				  </td>
				  <?php if ((count($res) - 1) > $i) {?>
					<?php } ?>
			<?php } ?>
					</table>
	        <?php
			$menu = ob_get_contents();
			ob_end_clean();
			return $menu;
		}
	}//class PHP_fun()
?>

Open in new window


Menu Page: menu.php

<?php
	include("functions.php");
	$db = new PHP_fun;
?>

<!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=utf-8" />
<meta name="keywords" content="" />
<title></title>
<script language="javascript">
	function redirect(url)
	{
		location.href = url;
		return false;
	}
	function showId(id)
	{
		var obj = document.getElementById(id);
		obj.style.display = 'block';
		return false;
	}
	function hideId(id)
	{
		var obj = document.getElementById(id);
		obj.style.display = 'none';
		return false;
	}
</script>

</head>

<body>
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>

        <td width="11%"><?=$db->getMenu(0);?></td>

      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

Open in new window

0
 
LVL 10

Accepted Solution

by:
TRW-Consulting earned 500 total points
ID: 34268728
I haven't tested this, and I have to leave for a few hours, but I believe all you need to do is change this line in the getChild() function:

  $s = "SELECT main_cat.*,  product.* FROM (product RIGHT JOIN main_cat ON main_cat.id=product.prod_catid) where parentid = '$id' ";

To this:

  $s = "SELECT prod_catid as id, product.prod_id FROM product where prod_catid = '" . $id . "'";
0
 

Author Comment

by:jayseena
ID: 34272644
I think I am very close to my goal. Will get back to you later.
Thanks for your efforts.
0
 

Author Comment

by:jayseena
ID: 34290621
I am yet to get this working, but don't need a support at this time. I will close this topic by tomorrow
0
 

Author Closing Comment

by:jayseena
ID: 34300219
Thanks for all your help TRW-Consulting.
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34301574
Glad I could be of service.  Good luck with that project!
0
 

Author Comment

by:jayseena
ID: 34303262
Sorry about that, I am running into another problem with this. If this is gonna be a complex one, I will open another thread. Please let me know if you can assist further on this.


The working menu is like this now

Product1

Product2 -----> Sub Product 1
               -----> Sub Product 1

Product 3 -----> Sub Product 1 > SubSub Product1

The Problem:

All works fine, except that when we link the menu items to the product page, we don't have anything to show for the main or sub category until we come to the last item in the tree.

I thought of two options:
1. To show the full category items page from where the user will go to the individual product detail page. I thought I will use a query to choose all products from products table that contain the category ID. But this won't work as we will not have a foreign ID present all the time for a category.
2. I considered a conditional region. With this I wanted to achieve an active menu link, if there is an category entry in product table or else no active link
I used the below query to select all category IDs that has presence in product table.
SELECT main_cat.id
FROM main_cat AS main_cat
LEFT JOIN (select distinct prod_catid from product) AS product ON product.prod_catid = main_cat.id
WHERE product.prod_catid IS NULL

Open in new window

The query worked fine. As always, then on I am totally blank on what to do!
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34306814
I'm not sure exactly what you're referring to, but maybe this is something close?  Perhaps you could create links for the categories similar to what you're doing for the products using something like 'http://localhost/cat_id.php?cat_id='

Then this 'cat_id.php' would be smart enough to recognize categories and sub-categories.
0
 

Author Comment

by:jayseena
ID: 34307211
I will try this.
0
 

Author Comment

by:jayseena
ID: 34316640
TRW-Consulting, I have posted this question again at ID: 26668711. Could you be in assistance further, please.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mysql Crashing Intermittently 16 49
mysql left join sentence 7 22
Why does my array not "dump?" 5 20
Adjust the position 3 13
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now