Jump to content


Photo

Multi Numbers problem


  • Please log in to reply
11 replies to this topic

#1 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 07:24 PM

I am trying to get multiple number is 1 if statement here is an example

if ($latitude==1||2||3||4||5 AND $longitude==1||2||3||4||5){

It doesn't work the way I want it to, I want every cordante from long 1, lat 1 to long 5,lat 5

#2 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 18 July 2006 - 07:46 PM

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?
Zend Certified Engineer (ZEND001989)
www.willfitch.com

#3 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 18 July 2006 - 07:48 PM


if ($latitude==1||2||3||4||5 AND $longitude==1||2||3||4||5){
Try:


if (($latitude==1||2||3||4||5) && ($longitude==1||2||3||4||5)){


#4 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 07:48 PM

well $latitude and $longitude are varibles that take a row from mySQL

#5 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 18 July 2006 - 07:50 PM

Would you post a code snippet besides that particular line so we can see what you are doing?
Zend Certified Engineer (ZEND001989)
www.willfitch.com

#6 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 07:53 PM

I tried

if (($latitude==1||2||3||4||5) && ($longitude==1||2||3||4||5)){

No luck on 6,6 I still got the massage

$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!";
}



#7 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 18 July 2006 - 07:53 PM

Did you try the code that I suggested, and did it give diffrerent results?

#8 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 08:10 PM

ChaosXero - my previous post said it

#9 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 18 July 2006 - 08:13 PM

Try a $latitude<6 && $longitude<6 (and add >0 if you like).  If it MUST be an int, try isint() also.

#10 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 08:18 PM

Thank you very much! That never even crossed my mind  ;D It has been a long day...

#11 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 18 July 2006 - 08:22 PM

No problem.  It's always fun to help other people out. (Mostly because they help me when I have questions)

#12 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 18 July 2006 - 08:28 PM

for the record, you have to explicitly set each condition within an if():

<?php
if (($long == 1 || $long == 2 || $long == 3) && ($lat == 1 || $lat == 2 || $lat == 3))
{

}
?>

etc.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users