Chevy Posted July 18, 2006 Share Posted July 18, 2006 I am trying to get multiple number is 1 if statement here is an example[code]if ($latitude==1||2||3||4||5 AND $longitude==1||2||3||4||5){[/code]It doesn't work the way I want it to, I want every cordante from long 1, lat 1 to long 5,lat 5 Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/ Share on other sites More sharing options...
willfitch Posted July 18, 2006 Share Posted July 18, 2006 This sounds like something that should be done on the database side to prevent giving birth to spaghetti code. Have you tried a query like:SELECT * FROM table WHERE latitude BETWEEN 1 AND 5 AND longitude BETWEEN 1 AND 5? Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60085 Share on other sites More sharing options...
ChaosXero Posted July 18, 2006 Share Posted July 18, 2006 [quote author=Chevy link=topic=101020.msg399387#msg399387 date=1153250641][code]if ($latitude==1||2||3||4||5 AND $longitude==1||2||3||4||5){[/code]Try:[/quote][code]if (($latitude==1||2||3||4||5) && ($longitude==1||2||3||4||5)){[/code] Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60088 Share on other sites More sharing options...
Chevy Posted July 18, 2006 Author Share Posted July 18, 2006 well $latitude and $longitude are varibles that take a row from mySQL Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60089 Share on other sites More sharing options...
willfitch Posted July 18, 2006 Share Posted July 18, 2006 Would you post a code snippet besides that particular line so we can see what you are doing? Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60091 Share on other sites More sharing options...
Chevy Posted July 18, 2006 Author Share Posted July 18, 2006 I tried [code]if (($latitude==1||2||3||4||5) && ($longitude==1||2||3||4||5)){[/code]No luck on 6,6 I still got the massage[code]$latitude = $row['latitude'];$longitude = $row['longitude'];$totalfish = $row['totalfish'];if ($process == play){if (isset($_POST["right"])) {$latitude++; mysql_query("UPDATE table SET latitude='$latitude' WHERE username='$MySN'")or die(mysql_error());}if (isset($_POST["left"])) {$latitude--; mysql_query("UPDATE table SET latitude='$latitude' WHERE username='$MySN'")or die(mysql_error());}if (isset($_POST["up"])) {$longitude++; mysql_query("UPDATE table SET longitude='$longitude' WHERE username='$MySN'")or die(mysql_error());}if (isset($_POST["down"])) {$longitude--; mysql_query("UPDATE table SET longitude='$longitude' WHERE username='$MySN'")or die(mysql_error());}if ($latitude==1||2||3||4||5 AND $longitude==1||2||3||4||5){ echo "Testing this cordnate!";}[/code] Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60095 Share on other sites More sharing options...
ChaosXero Posted July 18, 2006 Share Posted July 18, 2006 Did you try the code that I suggested, and did it give diffrerent results? Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60098 Share on other sites More sharing options...
Chevy Posted July 18, 2006 Author Share Posted July 18, 2006 ChaosXero - my previous post said it Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60120 Share on other sites More sharing options...
ChaosXero Posted July 18, 2006 Share Posted July 18, 2006 Try a $latitude<6 && $longitude<6 (and add >0 if you like). If it MUST be an int, try isint() also. Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60124 Share on other sites More sharing options...
Chevy Posted July 18, 2006 Author Share Posted July 18, 2006 Thank you very much! That never even crossed my mind ;D It has been a long day... Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60129 Share on other sites More sharing options...
ChaosXero Posted July 18, 2006 Share Posted July 18, 2006 No problem. It's always fun to help other people out. (Mostly because they help me when I have questions) Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60132 Share on other sites More sharing options...
akitchin Posted July 18, 2006 Share Posted July 18, 2006 for the record, you have to explicitly set each condition within an if():[code]<?phpif (($long == 1 || $long == 2 || $long == 3) && ($lat == 1 || $lat == 2 || $lat == 3)){}?>[/code]etc. Link to comment https://forums.phpfreaks.com/topic/14962-multi-numbers-problem/#findComment-60137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.