Where is says 1-5 I need to check if type= 1 2 3 4 or 5 and not return $error= True;. I dont know how....Pleas help. Thanks ALOT.PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1-5) {
$error = True;
}
Printable View
Where is says 1-5 I need to check if type= 1 2 3 4 or 5 and not return $error= True;. I dont know how....Pleas help. Thanks ALOT.PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1-5) {
$error = True;
}
PHP Code:for ($x=1; $x<=5; $x++){
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != $x) {
$error = True;
}
}
if you do it that way Gimlin then it will let whatever number it is not through.
you will have to check for each individual number.
it looks ugly but if you need to check for numerous numbers than that is the way.PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1 || $_GET['type'] != 2 || $_GET['type'] != 3 || $_GET['type'] != 4 || $_GET['type'] != 5) {
$error = True;
}
let me think on this as it seems there is another way.
Personally I prefer the switch statement:
-MattPHP Code:if (isset($_GET['type']) || $_GET['artist'] == "" || $_GET['title'] == "")) {
switch ($_GET['type']) {
case 1:
// If type equals 1
break;
case 2:
// If type equals 2
break;
case 3:
// If type equals 3
break;
case 4:
// If type equals 4
break;
case 5:
// If type equals 5
break;
default:
// If type does not equal 1-5
break;
}
}
gah! cant you just use this?
PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < 1 || $_GET['type'] > 5) {
$error = True;
}
I can't see why that wouldn't work, unless there's a problem with type equaling 0 or something greater than 5. I don't know.Quote:
Originally posted by Kagey
gah! cant you just use this?
PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < 1 || $_GET['type'] > 5) {
$error = True;
}
The only problem that could exist here is if he needs to do something if the type is equal to a number between 1 and 5.Quote:
Originally posted by Kagey
gah! cant you just use this?
PHP Code:if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < 1 || $_GET['type'] > 5) {
$error = True;
}
If he does need to, and if the code when type equals 1 needs to be different if type equals 2 then my switch statement would be best.
That's not what he was asking, though. I'm pretty sure he knows how to test if a variable is = to something.Quote:
Originally posted by cpradio
The only problem that could exist here is if he needs to do something if the type is equal to a number between 1 and 5.
If he does need to, and if the code when type equals 1 needs to be different if type equals 2 then my switch statement would be best.
I do not know about you or carp, but I change my mind on how I am going to code a project a thousand times a day. From my original idea comes a bigger and better idea, which then gets bigger and better, and so on.
I only suggested the switch method as its easy to read, easy to make more interactive, and could be beneificial depending on whether or not his objective is still the same. I agree that Kagey's method will work exactly as needed to, and should be used if his objective has not changed.
-Matt
so your trying to tell me that 2 is either less than 1 or greater than 5? news to me.Quote:
Originally posted by phpman
won't work
if type = 2 then it will give the error. he doesn't want the error if type= 1,2,3,4 or 5
Matt's is about the best way to do it.
I solved his problem over aim, a long while back.
I used
PHP Code:
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1 && $_GET['type'] != 2 && $_GET['type'] != 3 && $_GET['type'] != 4 && $_GET['type'] != 5) {
$error = True;
}
argggg, my appologies. I always get these backwards. you are right. sorry.
which is the same as the < > range checking one, only a lot messier.Quote:
Originally posted by Gimlin
I solved his problem over aim, a long while back.
I used
PHP Code:
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1 && $_GET['type'] != 2 && $_GET['type'] != 3 && $_GET['type'] != 4 && $_GET['type'] != 5) {
$error = True;
}
Your way is better, best, and brilliant. Happy :p I was just pointing out that there was no need to continue the thread.
Thanks everyone!