Jump to content

Help with ISSET and $_GET methods


dowsun18

Recommended Posts

Hi, I'm new to php and am attempting to build a site where the navigation and content is built with query functions. 

My current tables in my database are Categories, Products, and Variation.  So a person chooses a category -> then a product -> then a product page shows variations for that product. The problem I am currently having is after when a person selects a section the previous section selected is reset.  So lets a person selects a category the product list is shown, but when a person selects a product, the category is no longer selected in the navigation.  Or if someone selects product and sees all the variations, if he selects a variation the product ID is reset.  I've tried to comb through the internet for some type of solution.  I came across concatenating URL encode, but am not sure if this is the correct solution.  I tried concatenating one of my urls

with

"<a href=\"product_detail.php?cat=" . urlencode($sel_cat["id"]) . '&' . "product=" . urlencode($sel_product['id']) . '&' . "var=" . urlencode($var["id"]) .					"\"

 

its a bit of a stab in the dark. 

 

My $_GET function is

		function find_selected_product() {
	global $sel_cat;
	global $sel_product;
	global $sel_var;
	if (isset($_GET['cat'])) {
		$sel_cat = get_cat_by_id($_GET['cat']);
	} elseif (isset($_GET['product'])) {
		$sel_cat = NULL;
		$sel_product = get_product_by_id($_GET['product']);
	} elseif (isset($_GET['product'])) {					
		$sel_product = get_product_by_id($_GET['product']);
		$sel_var = get_default_var($sel_product['id']);				
	} elseif (isset($_GET['var'])) {	
		$sel_product = NULL;			//test
		$sel_var = get_variation_by_id($_GET['var']);				
	} else {
		$sel_cat = NULL;
		$sel_product = NULL;
		$sel_var = NULL;

	}
}

 

My navigation code is

	function public_navigation($sel_cat, $public = true) {
	$output = "<td class=\"c1\"><div class=\"sidenav\"><ul>";
	$cat_set = get_all_cats($public);
	while ($cat = mysql_fetch_array($cat_set)) {
		$output .= "<li>";
		if ($cat["id"] == $sel_cat['id']) { $output .= "<a class=\"current\""; }
		$output .= "<a href=\"index.php?cat=" . urlencode($cat["id"]) . "\">{$cat["cat_name"]}</a></li>";

	}
	$output .= "</ul>";

	return $output;
}

 

My product is divided into gender and is written like

 

	function cat_content_ladies($sel_cat, $sel_product, $female = true)
{
	$output = "<ul class=\"regions\">";
	$cat_set = get_all_cats($female);
		while ($cat = mysql_fetch_array($cat_set)) 
			{	if ($cat["id"] == $sel_cat['id'])
					{	
						$product_set = get_products_for_female($cat["id"], $female);
						$output .= "<tr>";						
							while ($product = mysql_fetch_array($product_set))
								{
									if ($cat["id"] == $sel_cat['id'])
										{
											$output .= "<tr>";	
											$output .= "<div class=\"pre\"><a href=\"product_detail.php?product=" . urlencode($product["id"]) . "\"></li>";
											$output .= "<img src=\"{$product["img_src"]}\" height=\"121\" width=\"121\">";
											$output .= "<div>{$product["prod_name"]}</a></div>";				
										}
								}
						$output .= "</tr>";			
					}
			}
		return $output;
}

 

My variation table is set up in thumb nails and is written in this function

function show_thumb($sel_product, $sel_var, $public = true)
{
	$output = "<ul class=\"subjects\">";
	$product_set = get_all_products($public);
	while ($product = mysql_fetch_array($product_set)) {
		$output .= "<li";
		if ($product["id"] == $sel_product['id']) { $output .= " class=\"selected\""; }
		//$output .= "><a href=\"product_detail.php?product=" . urlencode($product["id"]) . 
			//"\">{$product["id"]}</a></li>";
		if ($product["id"] == $sel_product['id']) {	
			$var_set = get_variations_for_product($product["id"], $public);
			$output .= "<ul class=\"pages\">";
			while ($var = mysql_fetch_array($var_set)) {
				$output .= "<li";
				if ($var["id"] == $sel_var['id']) { $output .= " class=\"selected\""; }
				$output .= "><a href=\"product_detail.php?var=" . urlencode($var["id"]) .
					"\">{$var["id"]}</a></li>";

			}
			$output .= "</ul>";
		}
	}
	$output .= "</ul>";
	return $output;
}

 

 

 

any light on this subject would be greatly appreciated.

 

Link to comment
Share on other sites

You're posting way too much code. You're going to have a hard time finding help when you overwhelm people with that much information.

 

$_GET will retrieve parameters from a URL. For example: $_GET['topic'] would contain 349165.0 for this page, I believe (SMF is weird). Now you don't need to urlencode integers. Just take out the urlencode altogether (unless they're strings, in which case keep them). Now I believe you're looking for something like this: http://www.mindpalette.com/tutorials/breadcrumbs/index.php ?

 

I don't think you'll find anyone here that will make you a navigation system just out of good will. It's gonna take some time to make. So keep looking on the net for solutions and ask for help when you have a more specific problem you've encountered.

Link to comment
Share on other sites

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.