|
-
Jul 25th, 2002, 07:24 PM
#1
Thread Starter
Hyperactive Member
See if type = 1 through 5 ...
PHP Code:
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1-5) {
$error = True;
}
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.
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
-
Jul 25th, 2002, 08:44 PM
#2
Fanatic Member
PHP Code:
for ($x=1; $x<=5; $x++){
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != $x) {
$error = True;
}
}
-
Jul 25th, 2002, 09:44 PM
#3
Frenzied Member
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.
PHP Code:
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != 1 || $_GET['type'] != 2 || $_GET['type'] != 3 || $_GET['type'] != 4 || $_GET['type'] != 5) {
$error = True;
}
it looks ugly but if you need to check for numerous numbers than that is the way.
let me think on this as it seems there is another way.
-
Jul 28th, 2002, 07:08 PM
#4
Fanatic Member
Personally I prefer the switch statement:
PHP 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;
}
}
-Matt
-
Jul 28th, 2002, 07:15 PM
#5
Hyperactive Member
gah! cant you just use this?
PHP Code:
if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < 1 || $_GET['type'] > 5) {
$error = True;
}
-
Jul 28th, 2002, 07:54 PM
#6
Stuck in the 80s
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;
}
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.
-
Jul 28th, 2002, 09:06 PM
#7
Fanatic Member
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.
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.
-
Jul 28th, 2002, 09:56 PM
#8
Stuck in the 80s
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.
That's not what he was asking, though. I'm pretty sure he knows how to test if a variable is = to something.
-
Jul 28th, 2002, 10:00 PM
#9
Fanatic Member
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
-
Jul 29th, 2002, 07:38 AM
#10
Hyperactive Member
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.
so your trying to tell me that 2 is either less than 1 or greater than 5? news to me.
-
Jul 29th, 2002, 07:41 AM
#11
Fanatic Member
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;
}
-
Jul 29th, 2002, 07:41 AM
#12
Frenzied Member
argggg, my appologies. I always get these backwards. you are right. sorry.
-
Jul 29th, 2002, 07:45 AM
#13
Hyperactive Member
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;
}
which is the same as the < > range checking one, only a lot messier.
-
Jul 29th, 2002, 07:47 AM
#14
Fanatic Member
Your way is better, best, and brilliant. Happy I was just pointing out that there was no need to continue the thread.
-
Jul 29th, 2002, 11:01 AM
#15
Thread Starter
Hyperactive Member
Kevin Carpenter
Currently Working in the CAOS (CA Operating System) Group
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|