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.