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
https://forums.phpfreaks.com/topic/74256-solved-switch-help/
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
https://forums.phpfreaks.com/topic/74256-solved-switch-help/#findComment-375160
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.