Switch0r Posted June 12, 2006 Share Posted June 12, 2006 hey peeps, i wonder if anyone can help me with my predicament...im sure someone can, cos it should be fairly simple but the answer keeps evading me...here goes.i have some variables sent from a form, 10 in total, and i want to make sure that they meet a required level. i have var 1, and var a > i. I want either var 1 to equal 1 & a > i to be 0, or var 1 to be 0 and at least one of a > i to be 1, but not both at the same time...if that makes any sense at allany thoughts? this is driving me crazy :) Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/ Share on other sites More sharing options...
poirot Posted June 13, 2006 Share Posted June 13, 2006 That sounded a bit confusing, but I guess you may be looking for the XOR operator.[a href=\"http://www.php.net/manual/en/language.operators.logical.php\" target=\"_blank\"]http://www.php.net/manual/en/language.operators.logical.php[/a][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Xor - TRUE if either $a or $b is TRUE, but not both [/quote] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44815 Share on other sites More sharing options...
Switch0r Posted June 13, 2006 Author Share Posted June 13, 2006 well thats what i thought, and i'd been trying various methods of doing thatwhat i had so far is this: id make a check if var a > i is set to 1, and if so, update a check variable, to make sure at least one of them is set, then compare this check var with the value of var 1[code]if($var 1 < 1 xor $check_var < 1){update a second check variable}[/code]but either way it comes up with the same answer, with no vars selected, 1 or the other, or all selected... Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44877 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 [!--quoteo(post=383120:date=Jun 13 2006, 06:33 AM:name=Switch0r)--][div class=\'quotetop\']QUOTE(Switch0r @ Jun 13 2006, 06:33 AM) [snapback]383120[/snapback][/div][div class=\'quotemain\'][!--quotec--]well thats what i thought, and i'd been trying various methods of doing thatwhat i had so far is this: id make a check if var a > i is set to 1, and if so, update a check variable, to make sure at least one of them is set, then compare this check var with the value of var 1[code]if($var 1 < 1 xor $check_var < 1){update a second check variable}[/code]but either way it comes up with the same answer, with no vars selected, 1 or the other, or all selected...[/quote]what if you add =<[code]if($var 1 =< 1 xor $check_var =< 1){update a second check variable}[/code] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44882 Share on other sites More sharing options...
Switch0r Posted June 13, 2006 Author Share Posted June 13, 2006 well ive changed the plan slightly...hopefully less complicated now :)i now have 9 checkboxes on the form, and at least one of them needs to be checked to proceed.this is what ive got so far:[code]// setup$count = 0;if($var1 = 1){$count++;}if($var1 = 2){$count++;}if($var1 = 3){$count++;}if($var1 = 4){$count++;}if($var1 = 5){$count++;}if($var1 = 6){$count++;}if($var1 = 7){$count++;}if($var1 = 8){$count++;}if($var1 = 9){$count++;}// checkif($count = 0){Give error}[/code]only this still doesnt work Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44889 Share on other sites More sharing options...
d_barszczak Posted June 13, 2006 Share Posted June 13, 2006 [!--quoteo(post=383132:date=Jun 13 2006, 08:19 AM:name=Switch0r)--][div class=\'quotetop\']QUOTE(Switch0r @ Jun 13 2006, 08:19 AM) [snapback]383132[/snapback][/div][div class=\'quotemain\'][!--quotec--]well ive changed the plan slightly...hopefully less complicated now :)i now have 9 checkboxes on the form, and at least one of them needs to be checked to proceed.this is what ive got so far:[code]// setup$count = 0;if($var1 = 1){$count++;}if($var1 = 2){$count++;}if($var1 = 3){$count++;}if($var1 = 4){$count++;}if($var1 = 5){$count++;}if($var1 = 6){$count++;}if($var1 = 7){$count++;}if($var1 = 8){$count++;}if($var1 = 9){$count++;}// checkif($count = 0){Give error}[/code]only this still doesnt work[/quote]Your if statement is wrong here you need if($var1 == 9){$count++;} [i]note the 2 ==[/i] otherwise your applying a new value to $var1. Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44890 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 You have to use == as equal or you are setting the vars as new varable names.was betten dam lol[code]// setup$count = 0;if($var1 == 1){$count++;}if($var1 == 2){$count++;}if($var1 == 3){$count++;}if($var1 == 4){$count++;}if($var1 == 5){$count++;}if($var1 == 6){$count++;}if($var1 == 7){$count++;}if($var1 ==8){$count++;}if($var1 ==9){$count++;}// checkif($count == 0){Give error}[/code] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44891 Share on other sites More sharing options...
Switch0r Posted June 13, 2006 Author Share Posted June 13, 2006 well ive got them all with == instead, and no matter how many boxes i choose (other than 0), the $count remains at 0, muh? Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44892 Share on other sites More sharing options...
d_barszczak Posted June 13, 2006 Share Posted June 13, 2006 [!--quoteo(post=383135:date=Jun 13 2006, 08:28 AM:name=Switch0r)--][div class=\'quotetop\']QUOTE(Switch0r @ Jun 13 2006, 08:28 AM) [snapback]383135[/snapback][/div][div class=\'quotemain\'][!--quotec--]well ive got them all with == instead, and no matter how many boxes i choose (other than 0), the $count remains at 0, muh?[/quote]ok,as a test you could put a echo var1 to make sure that the variable is being passed.think you might need something like.[code]$var1 = $_POST['var1'];[/code]before your if statement. Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44893 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 [!--quoteo(post=383135:date=Jun 13 2006, 07:28 AM:name=Switch0r)--][div class=\'quotetop\']QUOTE(Switch0r @ Jun 13 2006, 07:28 AM) [snapback]383135[/snapback][/div][div class=\'quotemain\'][!--quotec--]well ive got them all with == instead, and no matter how many boxes i choose (other than 0), the $count remains at 0, muh?[/quote]Try like this for a moment what happens.[code]<?echo $var1;if($_POST('$submit') {$count = 0;if($var1 == 1){$count++;}if($var1 == 2){$count++;}if($var1 == 3){$count++;}if($var1 == 4){$count++;}if($var1 == 5){$count++;}if($var1 == 6){$count++;}if($var1 == 7){$count++;}if($var1 ==8){$count++;}if($var1 ==9){$count++;}if($var1 ==0){echo " Sorry i am not working!";}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44894 Share on other sites More sharing options...
d_barszczak Posted June 13, 2006 Share Posted June 13, 2006 This should grab the posted variable and place it in a local variable.to make sure the information has been passed you can delete the comment tags and the variable will be printed to the screen.[code]// setup$var1 = $_POST['var1'];// echo "$var1";$count = 0;if($var1 == 1){$count++;}if($var1 == 2){$count++;}if($var1 == 3){$count++;}if($var1 == 4){$count++;}if($var1 == 5){$count++;}if($var1 == 6){$count++;}if($var1 == 7){$count++;}if($var1 == 8){$count++;}if($var1 == 9){$count++;}// checkif($count == 0){Give error}[/code] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-44898 Share on other sites More sharing options...
poirot Posted June 13, 2006 Share Posted June 13, 2006 Wouldn't this block of code do the same as:[code]if ((int) $_POST['var1'] <= 0) { // give error} else { $count = 1;}[/code] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-45011 Share on other sites More sharing options...
Switch0r Posted June 13, 2006 Author Share Posted June 13, 2006 right, well...ive sorted it :)added the $_POST array vars for the comparison, but changed the check so it checks if its "on" or not, as i had previously thought that checkboxes gave either 1 (checked) or 0 (blank), which apparently is untrue as it comes up as: on (checked) or empty var (blank)thanks for the help tho peeps [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] Link to comment https://forums.phpfreaks.com/topic/11814-solved-variable-comparisonlogical-operator-problem/#findComment-45179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.