Re: help out a noob w/ include & switch?

From: Date: Tue, 20 Sep 2005 23:15:10 +0000
Subject: Re: help out a noob w/ include & switch?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-222821@lists.php.net to get a copy of this message
jay thompson wrote:
index.php: <?php
        include 'content.php';   //sets the section title
        echo $title;
?> <?php
        include 'navigate.php';  //sets appropriate navigation menu
        echo $navigate;
?> <?php
        echo $content;   //loads body text
?>
There is no need to switch in and out of PHP there. Replace all the ?> immediately followed by <?php with nothing.
content.php: <?php switch ($cont) {
        case artist1:
                $title = 'event title';
                $content = '<p>some text</p>
                <p>some more text</p>
                <p class="sig">- artist name</p>';
                break;
        case artist2,3,4:
                [...]
                break;
        default:
                $title = 'event title';
                $content = '<p>some text</p>
                <p>some more text</p>
                <p class="sig">- artist name</p>';
                break;
} ?>
Unless you really have a constant defined called artist1, you probably want to rewrite the case statements as: case 'artist1': [...] case 'artist2,3,4': [...] etc (with the quotes added). If you actually mean 'artist2', 'artist3', and 'artist4' as separate artists, then you'll need to do: case 'artist2': case 'artist3': case 'artist4': separately.
navigate.php: <?php switch ($nav) {
        case 1:
                $navigate = '<ul><li><a href="index.php?nav=1&amp;cont=artist1">Link
title<br />by artist1</a></li><li><a href="index.php?nav=2&amp;cont=artist2">link title<br />by artist2</a></li><li><a href="">some more stuff</a></li><li><a href="">Contact</a></li></ul>';
                break;
        case 2,3,4:
                [...]
                break;
as far as I know, you need to actually do these as separate case statements: case 2: case 3: case 4: [...] break;
        default:
                $navigate = '<ul><li><a href="index.php?nav=1&amp;cont=artist1">Link
title<br />by artist1</a></li><li><a href="index.php?nav=2&amp;cont=artist2">link title<br />by artist2</a></li><li><a href="">some more stuff</a></li><li><a href="">Contact</a></li></ul>';
                break;
} ?>
-- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/

« previous php.general (#222821) next »