I am using this line of code to test for a price - if(empty($line['price']))
-
{
-
$err .= '<pre>No Price for '.print_r($line,1).'</pre>';
-
return false;
-
}
The price comes from a database as DECIMAL and I am suprised 0.00 is not 'empty'. Is this normal behaviour?
It does suit my purposes as there is a difference between free-of-charge 0.00 and a missing price '', which I am tyring to trap.
9 7574
0.00 is not empty. It's a number. You'll just need a logical or to test for the 0 case.
you probably need to write in the IF condition this:
empty($line['price'] === false
With that you can difference if is a 'really' false or other value
0.00 is not empty. It's a number.
it’s not a number either, it’s a string (like anything you get off the $_POST/$_GET arrays).
it’s not a number either, it’s a string (like anything you get off the $_POST/$_GET arrays).
It is directly from a database via mssql functions not a web-form.
But the important thing is, 0.00 is not empty - ever, so my test above is fine as free of charge goods will have a 0.00 price,
and un-priced goods will be NULL in the database and need to be trapped.
Thanks for all the comments
you’re right, I misread that part. you could simply test the datatype with var_dump(), though I suspect even DB results are strings (not much different from $_POST)
though I suspect even DB results are strings (not much different from $_POST)
Interesting point, I have never investigated this.
But I have found myself having to cast (float) in php doing calculations,
even though the data from the DB is supposedly in a numeric format.
well, I have never doubted this as you send/get data in a serialized format. and I’m pretty sure the mysql functions don’t do any back conversion.
it might be different if you used prepared statements and have bound a parameter.
according to php manual a variable is empty if meeting anyone of the following case: -
"" (an empty string)
-
0 (0 as an integer)
-
"0" (0 as a string)
-
NULL
-
FALSE
-
array() (an empty array)
-
var $var; (a variable declared, but without a value in a class)
-
-
-
if("0.00" == 0) echo "Just FYI, this returns true.";
-
else echo "Surprised if it doesn't!";
-
-
DM
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Martin Lucas-Smith |
last post by:
I wrote the function below as part of a larger class.
The fopen stage works, and, as according to the documentation at
www.php.net/fopen that succesfully creates a new file.
The fwrite stage...
|
by: annie |
last post by:
Hi
I've got two linux boxes running redhat9 and either PHP Version 4.2.2
or PHP Version 4.3.7. The file structure is set up the same on both
machines and both files exist. The problem is not...
|
by: lkrubner |
last post by:
www.php.net says:
>>>>>>>>>>>>
Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query()
returns a resource identifier or FALSE if the query was not executed
correctly. For other type of...
|
by: Boris Zakharin |
last post by:
I am using the .Net framework 1.1 and VS.NET 2003.
I have some code where, for some reason, IsPostBack returns false messing up
my code. I have a DataGrid, whose data I am trying to edit. Instead...
|
by: Sacha Korell |
last post by:
First of all, sorry for cross-posting, but this newsgroup is much busier
than "aspnet.mobile".
I'm trying to create a portal page that redirects depending on the device
that is connecting.
...
|
by: Markus Ernst |
last post by:
Hi
In an application installed with PHP5 it looks like ftp_nlist() returns
false if the directory is empty, instead of an empty array as it should
according to the manual. On the original server...
|
by: Italian Pete |
last post by:
Hi,
I have a website sitting on a server (ServerA) with images to be
displayed sitting on a separate server (ServerB) on the same network.
I am trying to test for the existance of an image...
|
by: snow |
last post by:
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(filePath) always return false in
release mode. How could I make this function...
|
by: khalid Ahmed |
last post by:
I'm attempting to execute a SQL SELECT query but it doesn't seem to be returning any records. I've confirmed that the connection is actually opening and when I tried to execute the same query on...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |