Results 1 to 15 of 15

Thread: See if type = 1 through 5 ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296

    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

  2. #2
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    PHP Code:
    for ($x=1$x<=5$x++){

    if (
    $_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != $x) {
            
    $error True;
    }



  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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'] != || $_GET['type'] != || $_GET['type'] != || $_GET['type'] != || $_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.

  4. #4
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    gah! cant you just use this?
    PHP Code:
    if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < || $_GET['type'] > 5) {
            
    $error True;


  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Kagey
    gah! cant you just use this?
    PHP Code:
    if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < || $_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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by Kagey
    gah! cant you just use this?
    PHP Code:
    if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] < || $_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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  10. #10
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    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.

  11. #11
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    I solved his problem over aim, a long while back.

    I used

    PHP Code:

    if ($_GET['artist'] == "" || $_GET['title'] == "" || $_GET['type'] != && $_GET['type'] != && $_GET['type'] != && $_GET['type'] != && $_GET['type'] != 5) {
            
    $error True;


  12. #12
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    argggg, my appologies. I always get these backwards. you are right. sorry.

  13. #13
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    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'] != && $_GET['type'] != && $_GET['type'] != && $_GET['type'] != && $_GET['type'] != 5) {
            
    $error True;

    which is the same as the < > range checking one, only a lot messier.

  14. #14
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Your way is better, best, and brilliant. Happy I was just pointing out that there was no need to continue the thread.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    Thanks everyone!
    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
  •  



Click Here to Expand Forum to Full Width