Jump to content

[SOLVED] Value lower than 0


monkeybidz

Recommended Posts

Is there anything else that could represent less than 0 or empty besides:

 

<0

 

I have this to work with:

 

if(empty($miles) || !$miles) {

    return false;

}

 

The problem is that 0 represents an actual good value from my database.

 

Example:

 

if($zip1 == $zip2 || $zip2 == $zip1) {

    $miles = 0 ;

}

 

This is good.

 

Problem:

 

if(empty($miles) || !$miles) {

    return false;

}

 

This takes 0 for empty. Can i do something to make it ignore the 0 and act on stricktly empty?

 

Link to comment
Share on other sites

Did not work. Returns false to empty, 0 or anything above 0.

The database info is just lattitude and longitude which are called by the script depending on the users zip code form input result which are then calculated by the script to determine the distance between the two.

 

When $zip1 == $zip2 the result is 0 because it is the same city. When the information does not exsist in database for a certain zip code the script is supposed to catch this, but it is not. Maybe the problem lies in this code.

 

$z = new zipcode_class;

$miles = $z->get_distance($zip1, $zip2);

 

if (empty($zip1)|| $zip1 === 'false'.$z){
     $msg[] = $error1;
}

 

Same code applies to $zip2.

 

Link to comment
Share on other sites

It fails all above 0 using !$miles >=0.

 

I found this article that may be the cause:

 

empty("0")

The perhaps most cotroversal change in behavior has happend to the behavior of the empty(). A String containing only the character '0' (zero) is now considered empty while it wasn't in PHP 3.0.

 

This new behavior makes sense in web applications, with all input fields returning strings even if numeric input is requested, and with PHP's capabilities of automatic type conversion. But on the other had it might break your code in a rather subtle way, leading to misbehavior that is hard to track down if you do not know about what to look for.

 

Link to comment
Share on other sites

I managed to trick the script by putting the include datacheck passed the problem point and converting the miles from 0 to 1 before the data check. Now the data check file will read empty or 0 as true empty. I have nothing else that could = 0 anymore.

 

 

$z = new zipcode_class;

$miles = $z->get_distance($zip1, $zip2);

$english_format_number = number_format($miles);//Added to round off mileage//

 

if($zip1 == $zip2 || $zip2 == $zip1) {

    $miles = 1;

}

 

include ('datacheck1.php'); // This was at the top of the page before. Just moved it down and changed  $miles. All your code would have probably worked had i done this change earlier.

 

Thank guys!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.