Reputation: 283
I'm creating a mega menu for a clothing e-commerce site. The categories are split between New In, Women and Men. New In will just be links straight to particular products but I want the Women and Men categories to be linked to the relevant categories via just two pages. So underneath the Women category will be skirts and tops for example.
My code is starts off as...
$ItemCategory = ['$category'];
$category = "";
switch ($_GET['$category']) {
case "Women";
// the difference in variables go here;
break;
case "Men";
// the difference in variables go here;
break;
}
I don't know if I'm going about this the right way or what way to approach it. Obviously the bit where the comment is would be where I would enter each category. Although I'm not sure what would go here.
Also, what would the link be for skirts for example? Would it be
<a href="http://mysite.com/store.php?gender=Women&category=skirts">Skirts</a>
Or am I totally missing the point?
Upvotes: 0
Views: 313
Reputation: 2535
That needs a combined switch or an if-else:
$ItemCategory = $_GET['category'];
$gender = $_GET['gender'];
if($gender == 'Women'){
switch ($ItemCategory) {
case "Skirts":
// content
break;
case "Hats":
// content
break;
}
}else if($gender == 'Men'){
switch ($ItemCategory) {
case "Ties":
// content
break;
case "Trousers":
// content
break;
}
}
Another way would be to store the categories in the database (which you probably do anyways) and define which category belongs to men and women. Then you could only use a single category id to navigate.
Upvotes: 1
Reputation: 761
$ItemCategory = $_GET['category'];
$category = "";
switch ($ItemCategory) {
case "Women":
// the difference in variables go here;
break;
case "Men":
// the difference in variables go here;
break;
}
Upvotes: 0