GregL83 Posted April 26, 2007 Share Posted April 26, 2007 Simple questions for the noob...I have an if statement where I want true to be returned dependent on three things. The first must always be true and the second and third must have one of the two true...I am not sure how the operation is conducted... if(isset($_POST['submit']) && $item = "width" or $item = "height") { $update["$item"] = $_POST[$item]."px"; } Thanks for the help.. Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 if(isset($_POST['submit']) && $item = "width" || isset($_POST['submit']) && $item="height"){ $update[$item] = $_POST[$item] . "px"; } Quote Link to comment Share on other sites More sharing options...
btherl Posted April 26, 2007 Share Posted April 26, 2007 You can use brackets to enforce the order of evaluation. Another method is to create temporary variables to hold intermediate results, and then use those temporary variables in the "if". Temporary variables often results in MUCH more readable code. Example: $submitted = isset($_POST['submit']; $item_valid = ($item == "width" or $item == "height"); if ($submitted && $item_valid) { } Also note that you must use == or === when testing values, NEVER =. "=" will set the variable to a new value. Quote Link to comment Share on other sites More sharing options...
GregL83 Posted April 26, 2007 Author Share Posted April 26, 2007 Thanks for the help. Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 $submitted = isset($_POST['submit']); * You can also do this: $submit = (isset($_POST['submit'])) ? $_POST['submit'] : NULL; // If submit is set, then $submit is = $submit, else its NULL. if($submit){ if($item == "width" OR $item == "height"){ # do this } } Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 like this: <?php if(isset($_POST['submit']) && ($item = "width" || $item = "height")) { $update['$item'] = $_POST[$item'] . 'px'; } ?> 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.