Jump to content

[SOLVED] Switch Help


Rineru

Recommended Posts

I have a code similar to this:  (Cut down and renamed)

 

<?php
($_GET['id']) 

if ($id == 'news') {
include 'blahblah.php';
}

//info
elseif ($id == 'rock') {
include 'rockblahblah.php';
}

<-- other Elseifs -->

else {
require_once 'blahblah.php'; 
}
?>

 

Included on my main page.  What I want to do, I had working with this

When they go to main.php I want the news to be the shown object,  and if they navigate to something else.

main.php?id=rock  (that should be the link to it)  I want rock's to be included.

 

But for some reason news in the only thing included always.

 

I think there is a small piece of code missing from the main.php.

 

Came someone help me or direct me to a place that can?

Link to comment
Share on other sites

Aside from not assigning $_GET['id'] to $id I didn't see any problems, though it would be more efficient to use a switch.

 

<?php

$id = (isset($_GET['id']) ? $_GET['id'] : '');

switch ($id) {
case 'news':
	include 'blahblah.php';
	break;
case 'rock':
	include 'rockblahblah.php';
	break;
default:
	require_once 'blahblah.php';
}
?>

Link to comment
Share on other sites

And even easier to create an array of valid files and simply check that and dynamically include.

 

<?php

 $valid = array('news','rock');
 if (in_array($_GET['id'])) {
   include $_GET['id'] . '.php';
 } else {
   include 'default.php';
 }

?>

Link to comment
Share on other sites

What's wrong with this?

 

<?php
$id = $_GET['id'];
include("include/session.php");

if ($id == 'news') {
include 'news/news.php';
}

//Start of Rock
elseif (($id == 'rock')&&($session->logged_in)) {
include 'rock/index.php';

<-- more elseif's and else-->

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.