Jump to content

[SOLVED] or condition in if statement


jbingman

Recommended Posts

im trying to put in content but restrict it to certain pages. The index page, the about us page, and the contact page. I use:

if($_GET['page'] == 'index' || 'about' || 'contact') {
//content here
}elseif($_GET['page'] == 'videos') {
//content here
}elseif($_GET['page'] == 'graphics') {
//content here
}elseif($_GET['page'] == 'web') {
//content here

but that doesnt work. it puts that content in ALL the pages. It works if i take out the other 2 'or' statements in the first if. (the "|| 'about' || 'contact'")

 

Does anyone know why? or how to make that work? thanks.

 

Link to comment
Share on other sites

You need to use

<?php
if($_GET['page'] == 'index' || $_GET['page'] == 'about' || $_GET['page'] == 'contact') {
?>

 

But I would use a switch statement:

<?php
if (isset($_GET['page']))
   switch ($_GET['page']) {
       case 'index':
       case 'about':
       case 'contact':
//
//       code
//
          break;
       case 'videos':
//
//       code
//
          break;
       case 'graphics':
//
//       code
//
          break;
      case 'web':
//
//       code
//
          break;
      default:
//
//       default code
//
          break;
    }
?>

 

Ken

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.