Page 1 of 1

Help with code (simple)

Posted: Tue Jan 27, 2004 10:54 am
by grudz
this is my code

Code: Select all

$value = $_GET['type'];
switch($value) {
    case $HTTP_GET_VARS['type']:
        $name = $row_List["name"];
        $streetnumber = $row_List["streetnumber"];
        $address = $row_List["address"];
        $smalldesc = $row_List["smalldescription"];
        $location = $row_List["location"];
        $icons = $row_List["icons"];
        $pic = $row_List["smallpic"];
        $type = $row_List["type"];
        break;

?>

that works perfect, but now i want to add a $_GET['name'] because im also using this page as a search results page. Here is what i mean (the syntax is off though)

Code: Select all

$value = $_GET['type'] AND $value = $_GET['name']  
switch($value) {
    case $HTTP_GET_VARS['type']:
        $name = $row_List["name"];
        $streetnumber = $row_List["streetnumber"];
        $address = $row_List["address"];
        $smalldesc = $row_List["smalldescription"];
        $location = $row_List["location"];
        $icons = $row_List["icons"];
        $pic = $row_List["smallpic"];
        $type = $row_List["type"];
        break;
        
    case $HTTP_GET_VARS['type'] AND $HTTP_GET_VARS['name']:
        $name = $row_List["name"];
        $streetnumber = $row_List["streetnumber"];
        $address = $row_List["address"];
        $smalldesc = $row_List["smalldescription"];
        $location = $row_List["location"];
        $icons = $row_List["icons"];
        $pic = $row_List["smallpic"];
        $type = $row_List["type"];
        break;
}
?>

so how do i structure this? can i have everything in one "switch statement" or do i need more than one?

thanx

Posted: Tue Jan 27, 2004 12:40 pm
by Gen-ik
Switch() is designed to execute one piece of code depending on the value of a single var. You can however have a switch() within a switch() but you will need to decide if using a switch() is going to be better than using an if() for your code.

Code: Select all

<?php

$type = "egg";
$name = "chips";

switch($type)
{
    case "egg":
        switch($name)
        {
            case "chips":
                echo "Egg and Chips";
            break;
        }
    break;
}

?>

Posted: Tue Jan 27, 2004 12:44 pm
by grudz
thanx...ill look into the if()