Jump to content

[ resolved ] help with url variables.


eightFX

Recommended Posts

I am having an issue trying to get my variables from the URL to work properly. What I am trying to do is print something different depending on what the variable is equal to. Basically this is what I have:

URL IS: www.url.com/?id=

CODE:
[code]
$id = $_GET['id'];

if ($id == ('A' || 'B' || 'C')) {

echo 'this $id ' ;

} elseif ($id == 1) {

echo 'that $id' ;

} elseif ( $id = '' ) {

echo 'no id set';

}

[/code]

The issue is that if the URL is set to: www.url.com/?id=1

It prints out: this 1

Instead of printing out: that 1

If this does not make any sense please let me know I will try to elaborate. Help greatly appreciated. Thank You!
Link to comment
Share on other sites

it shouldn' tbe printig any variables as your using single quotes. You might try...

[code=php:0]
$id = $_GET['id'];

if ($id == 'A' || $id == 'B' || $id == 'C') {

  echo "this $id " ;

} elseif ($id == 1) {

  echo "that $id" ;

} elseif ( $id == '' ) {

  echo 'no id set';

}
[/code]
Link to comment
Share on other sites

Here's another solution that uses the switch statement:
[code]<?php
$id = $_GET['id'];
switch ($id) {
    case 'A':
    case 'B':
    case 'C':
      echo "this $id";
      break;
    case 1:
      echo "that $id";
      break;
    default:
      echo "no id set or is invalid";
}
?>[code]

Ken[/code][/code]
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.