Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP - if statement problem

Options
  • 18-06-2007 12:59am
    #1
    Registered Users Posts: 1,987 ✭✭✭


    The code below basically checks the page variable against the result variable, say result is 1 and page is one then releases() will be called but say result is 1 and page is greater the 1 like 2 or 4000 releases() is still called when error should be! Is there something i'm missing??

    [PHP]if(($result <= $_GET) || ($result == $_GET))
    {
    releases();
    }
    else
    {
    error();
    }[/PHP]


Comments

  • Registered Users Posts: 5,618 ✭✭✭Civilian_Target


    Well, that's an odd bit of code. How about
    if($result > $_GET['page']) error() ;
    else releases();
    

    Does that behave as you expect?
    Have you tried printing both the variables to see if they have the values you expect?


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    No that didn't work, heres what im using now, it stops zero from being entered but releases is still being displayed for every number except zero.

    All variables are correct!
    [PHP]if(($result <= $_GET) && ($_GET >= 1))
    {
    releases();
    }
    else
    {
    error();
    }[/PHP]


  • Registered Users Posts: 5,618 ✭✭✭Civilian_Target


    Well, first, you should be translating what you're saying into code to help readability. ie.
    if($_GET['page'] == 0 || $_GET['page'] > $result) error();
    else            releases();
    
    Doing that will make things much more easy to follow. However, the code snippet you're giving seems fine (my PHP's a bit rusty, but it looks OK) - are releases() and error() doing what you've expected? Try putting print statements at the top of them! Are you sure you're reading for a _GET rather than _POST array? Have you actually tested the _GET var to make sure it's an integer? Consider adding an integer test to your if statement?


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Are you sure $result isn't coming back as an array?
    I'd say replace the each of the variables with fixed values in the evaluation... narrow down which variable isn't what you expected.
    Can't see any problems with the evaluation itself.


  • Registered Users Posts: 928 ✭✭✭jabberwock


    [PHP]
    if ( ($result == $_GET) && ($_GET > 0))
    {
    releases();
    }
    else
    {
    error();
    }
    [/PHP]

    if result==page# AND page# greater than 0
    call releases
    else
    call error

    is that what your trying to do?

    so for releases to be called the $result must be the same as the $_GET ??


  • Advertisement
  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Ok, this is what im at:

    - Once 'page is not 0 releases will be called
    - Once $result is less then or equal to 'page then releases is called
    - For everything else error is called

    $result is gotten by the below:
    [PHP]$result = check_rows("releases"); //Checks how many rows in the table
    $result = $result / 15; //Divides the number of rows in the table by 15(number of rows to be shown per page)
    $result = number_format($result); //turns result of division into a number[/PHP]


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    I got it, this is what im using now.
    [PHP]if(($_GET > 0) && ($result >= $_GET) && (is_numeric($_GET) == true))
    {
    releases();
    }
    else
    {
    error();
    }[/PHP]
    Thanks for all the help.


Advertisement