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
https://forums.phpfreaks.com/topic/28521-resolved-help-with-url-variables/
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]
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]

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.