eightFX Posted November 26, 2006 Share Posted November 26, 2006 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 1Instead of printing out: that 1If this does not make any sense please let me know I will try to elaborate. Help greatly appreciated. Thank You! Quote Link to comment Share on other sites More sharing options...
trq Posted November 26, 2006 Share Posted November 26, 2006 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] Quote Link to comment Share on other sites More sharing options...
eightFX Posted November 26, 2006 Author Share Posted November 26, 2006 Thanks for the reply Thorpe.The quotes were a mistype in my post, however I did change the first IF statement and it seems to be working fine now. Thank You! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 26, 2006 Share Posted November 26, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.