Help with code (simple)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Help with code (simple)

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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;
}

?>
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Post by grudz »

thanx...ill look into the if()
Post Reply