How to pass a hidden url variable from within the <li> </li>

Hello,

is there a way to pass/send a hidden url variable from within the <LI> tag

I high lighted the areas in question in red.

top of the script i have this line: $catID = $_GET[id] - works

$catID - is received via a url variable ($_GET[id]) and at the same time its also linked to other parts of the script. - works
$value2[‘node_inx’] is where the problem is.
the node_inx is also connected to $GET[id].

is there a way to pull out this variable –> &id='.$value2[‘node_inx’] and send the variable through a hidden field… i tried the input hidden field but didnt work.
is there an alternative option for sending a url variable…


	<ul id="menuList">';
		foreach($_SESSION['breadcrum']  AS $key1=>$value1)
		{ 	if($value1['node_inx'] == $catID)
			{	foreach($_SESSION['breadcrum'] as $key2=>$value2)
				{	if( $value1['node_inx'] == $value2['node_parent'])
					{	echo '<li> <a href="subcategory.php?idlist=' .  $value2['node_inx'] . '&catlist=' . $value2['node_name'] . '&id='.$value2['node_inx']. '">' . $value2['node_name']. '</a></li>';
					}										
	                        }// inner loop 2 								
			}
			}// outer loop 1
	echo '</ul>


Instead of using id again can you change the key to something else? node_inx for example.

For links use &amp; instead of &
    echo '<ul id="menuList">';
        foreach($_SESSION['breadcrum'] as $key1 => $value1)
        {     if($value1['node_inx'] == $catID)
            {    foreach($_SESSION['breadcrum'] as $key2 => $value2)
                {    if( $value1['node_inx'] == $value2['node_parent'])
                    {    echo '<li> <a href="subcategory.php?idlist=' .  $value2['node_inx'] . '&amp;catlist=' . $value2['node_name'] . '&amp;node_inx='.$value2['node_inx']. '">' . $value2['node_name']. '</a></li>';
                    }
                }// inner loop 2
            }
        }// outer loop 1
    echo '</ul>';

hi Drummin,

I think you helped me with other related scripting issues… thanks again.

i looked at this from several different angles and am still hitting the same wall… this problem is extended from the last post you helped me with.
basically what im trying to create is a classified ad script.
so far what i have
1 . the first page displays the entire category like kijiji. user clicks and moves to the subcategory page (variable passed to the subcategory page, categoryid: id
2. subcategory page takes the variable “id” and displays whatever subcategories within the main category( eg. clothing: -mens wear, -womens wear)
— all of this depends on the variable id.
— the variable id is also used to display breadcrumb as well as the tree like category links to the left of the screen .

this is where it gets tricky.
user clicks a sub category example womens wear, the page reloads. if the id variable isnt passed through the url the whole script collapses as the whole script is depended on the id variable.
just to through a kicker in the whole script, if i go back to its parent category the id variable changes and cant get back to the clothing category as now the id is changed… its just keeps going in circle…lol
been at this for 3 weeks and i think im making this simple script very complicated…

if i can just figure out how to send the id variable without including it in the <li> link it would i think will work…lol

Can you post a print_r() of your data array and session array? I will look at it when I get home.

Hi Drummin,

as per your request i also included image for a visual perspective.
left image, main category is ’ buy and sell’ and the links below should be clickable.
the image on the right… the links below clothing (womens wear), problem area… needs to be clickable so that i can display items posted in this category. having said that i need the variable id to maintain the page/ buy and sell/clothing category in place. without the id variable the page would not display correctly.

Thanks for your help.


$catID = $_GET['id'];

/* index - parent -    category  
     1   -   0    -   technology
     4   -   3    ------ computer
     7   -   4    -------- monitor
   */
/*****************************************************************************************/

echo '<ul>';
foreach ($testArray as $key1 => $value1)
{	if($value1['node_inx'] == $catID)
	{	if(!empty($value1['up3_inx']))
		{	echo '<li><a href="dbtest2.php?id='. $value1['up3_inx'] . '&par='. $value1['up3_parent'] . '&cat=' . $value1['up3_name'] . '">' . $value1['up3_name'] . '</a></li>'; }
		if(!empty($value1['up2_inx']))
		{	echo '<li><a href="dbtest2.php?id='. $value1['up2_inx'] .  '&par='. $value1['up2_parent'] . '&cat=' . $value1['up2_name'] . '">' . $value1['up2_name'] . '</a></li>'; }
		if(!empty($value1['up1_inx']))
		{	echo '<li><a href="dbtest2.php?id='. $value1['up1_inx'] .  '&par=' . $value1['up1_parent'] . '&cat=' . $value1['up1_name'] . '">' . $value1['up1_name'] . '</a></li>'; }
		if(!empty($value1['node_inx']))
		{	echo '<li><a href="dbtest2.php?id='. $value1['node_inx'] .  '&par=' . $value1['node_parent'] . '&cat=' . $value1['node_name'] . '">' . $value1['node_name'] . '</a></li>';  }
	}
}//end of outer foreach loop
echo '<ul>';

foreach($testArray AS $key4=>$value4)
{ 	if($value4['node_inx'] == $catID)
	{	foreach($testArray as $key5=>$value5)
		{	if( $value4['node_inx'] == $value5['node_parent'])
			{	echo '<li> <a href="dbtest2.php?idlist=' .  $value5['node_inx'] . '&catlist=' . $value5['node_name'] . '&id='.$value5['node_inx'] . '">' . $value5['node_name']. '</a></li>';  }		
			   
		}// inner loop 2 								
	}
}// outer loop 1

sample print_r(not sure if i should copy and past the entire data dump)



    [27] => Array
        (
            [node_inx] => 28
            [node_name] => clothing
            [node_parent] => 20
            [up1_inx] => 20
            [up1_name] => buy & sell
            [up1_parent] => 0
            [up2_inx] => 
            [up2_name] => 
            [up2_parent] => 
            [up3_inx] => 
            [up3_name] => 
            [up3_parent] => 
        )

    [28] => Array
        (
            [node_inx] => 29
            [node_name] => Furniture
            [node_parent] => 20
            [up1_inx] => 20
            [up1_name] => buy & sell
            [up1_parent] => 0
            [up2_inx] => 
            [up2_name] => 
            [up2_parent] => 
            [up3_inx] => 
            [up3_name] => 
            [up3_parent] => 
        )

    [29] => Array
        (
            [node_inx] => 30
            [node_name] => home, indoor
            [node_parent] => 20
            [up1_inx] => 20
            [up1_name] => buy & sell
            [up1_parent] => 0
            [up2_inx] => 
            [up2_name] => 
            [up2_parent] => 
            [up3_inx] => 
            [up3_name] => 
            [up3_parent] => 
        )

Why do you want to hide the variable?

It sound’s like you should reconsider the way your program works, because I think you might end up tieing yourself in knots if you go down this path. Or maybe not? Just my opinion.

I agree that this is getting out of hand, especially when looking at the array sample you posted. Using id’s for all categories is also complicating things as it takes that extra query to grab the name and then trying to tie things together and match this up. You links for example “could” give you a complete path for example ?cat=Clothing/Womens/Blouses&id=46. You then could explode(“/”,$_GET[‘cat’]) to give you an array to make your breadcrum and if the id is present show the item, if not list all items in this category by making a query based on the values of $_GET[‘cat’]. Sounds to me like a better approach.

Not sure if something like this might work.

<?php 
//Sample Result set
$result=array(
	26 => Array
		(
		'node_inx' => 20,
		'node_name' => "Light Blue Blouse",
		'up1_name' => "Blouses",
		'up2_name' => "Womens",
		'up3_name' => "Clothing",
		'up4_name' => "Buy & Sell"
		),
	27 => Array
		(
		'node_inx' => 22,
		'node_name' => "Levi 501",
		'up1_name' => "Jeans",
		'up2_name' => "Mens",
		'up3_name' => "Clothing",
		'up4_name' => "Buy & Sell"
		)
	);
//////////////
function safeurl($x){
	$r =str_replace("& ","&amp; ",$x);
	$r =str_replace(" ","%20",$r);
	return $r;
}
//////////////		
$links = array();  
$breadcrumbs = array();

foreach($result as $k => $arr):
	$precategories = array();
	krsort($arr);
	foreach($arr as $k2 => $arr2):
		if(!empty($arr2) && $k2 != 'node_name' && $k2 != 'node_inx'):
			$precategories[] = $arr2;
		endif;
	endforeach;
		 
	$categories = implode("/",safeurl($precategories)); 
	$id = $arr['node_inx'];
	$name = str_replace("& ","&amp; ",$arr['node_name']);   
	$breadcrumbs[] = implode(" &rsaquo;&rsaquo;&rsaquo; ",str_replace("& ","&amp; ",$precategories)); 
	$links[] = '<a href="?cat=' . $categories . '&amp;id=' . $id . '">' . $name . '</a>';  

endforeach;

echo "<pre>";
print_r($links); 
print_r($breadcrumbs); 
echo "</pre>";
		
//cat=Clothing/Womens/Blouses
?>

Looks like this.

Array
(
    [0] => Light Blue Blouse
    [1] => Levi 501
)
Array
(
    [0] => Buy & Sell &#8250;&#8250;&#8250; Clothing &#8250;&#8250;&#8250; Womens &#8250;&#8250;&#8250; Blouses
    [1] => Buy & Sell &#8250;&#8250;&#8250; Clothing &#8250;&#8250;&#8250; Mens &#8250;&#8250;&#8250; Jeans
)

If using names as get values, you’re going to have to nix that & from Buy & Sell. I edited the str_replace to replace with “and” instead of &. I also made a breadcrumb based on GET at the bottom. Anyway, you might be able to use some of it.

<?php
//Sample Result set
$result=array(
	26 => Array
		(
		'node_inx' => 20,
		'node_name' => "Light Blue Blouse",
		'up1_name' => "Blouses",
		'up2_name' => "Womens",
		'up3_name' => "Clothing",
		'up4_name' => "Buy & Sell"
		),
	27 => Array
		(
		'node_inx' => 22,
		'node_name' => "Levi 501",
		'up1_name' => "Jeans",
		'up2_name' => "Mens",
		'up3_name' => "Clothing",
		'up4_name' => "Buy & Sell"
		)
	);	
	
//////////////
function safeurl($x){
	$r =str_replace("& ","and ",$x);
	$r =str_replace(" ","%20",$r);
	return $r;
}
//////////////		
$links = array();
$breadcrumbs = array();

foreach($result as $k => $arr):
	$precategories = array();
	krsort($arr);
	foreach($arr as $k2 => $arr2):
		if(!empty($arr2) &&	$k2 != 'node_name' &&	$k2 != 'node_inx'):
			$precategories[] = $arr2;
		endif;
	endforeach;
		
	$categories = implode("/",safeurl($precategories));
	$id = $arr['node_inx'];
	$name = str_replace("& ","&amp; ",$arr['node_name']);
	$breadcrumbs[] = implode(" &rsaquo;&rsaquo;&rsaquo; ",str_replace("& ","&amp; ",$precategories));
	$links[] = '<a href="?cat=' . $categories . '&amp;id=' . $id . '">' . $name . '</a>';

endforeach;

echo "<pre>";
print_r($links);
//print_r($breadcrumbs);
echo "</pre>";

$breadcrumb = "";
function urltostring($x){
	$r = str_replace("%20"," ",$x);
	return $r;
}
if(isset($_GET['cat'])):
	$cats = explode("/",urltostring($_GET['cat']));
	
	$linkcat = array();
	$linkparts = array();
	foreach($cats as $cat):
		$linkcat[] = $cat; 	
		$sublink = implode("/",safeurl($linkcat));
		$linkparts[] = '<a href="?cat=' . $sublink . '">' . $cat . '</a>';
	endforeach;	
	
endif;	

if(isset($linkparts)):
	$breadcrumb .= implode(" &rsaquo;&rsaquo;&rsaquo; ",$linkparts);
	echo $breadcrumb;
endif;
?>