[PHP] Re: NULLS vs Empty result in PHP
using empty() is ´the right way to check a var for NULL or however, it also depends what MySQL has got as setuo definition for empty fields. on textfields u can define an epmty string as default. ralph_def...@yahoo.de Dan Shirah mrsqua...@gmail.com wrote in message news:a16da1ff0909230458o30d66186m75fc4fd0d1972...@mail.gmail.com... Morning! Just a quick question. Say I have a column in my database that could contain NULLS, empty spaces, or an actual value. If I do: $my_query = SELECT my_column FROM my_database WHERE 1 = 1; $my_result = ifx_query($my_query, $connect_id); while($row = ifx_fetch_row($my_result)) { $my_column = trim($row['my_column']); if ($my_column != ) { echo Test; } } The way PHP assigns the query results to the $my_column variable, wouldn't; if ($my_column != ) not do anything for the rows that contained NULLS or empty spaces? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: NULLS vs Empty result in PHP
using empty() is ´the right way to check a var for NULL or however, it also depends what MySQL has got as setuo definition for empty fields. on textfields u can define an epmty string as default. So say these are the first three results of my query: some text //The column actually has data //The column contains a series of spaces NULL //The column contains a NULL value As long as I trim() the result, if (!empty()) would skip any results where the column containsOR NULL, correct?
Re: [PHP] Re: NULLS vs Empty result in PHP
Ralph Deffke wrote: using empty() is ´the right way to check a var for NULL or Empty will also match a string containing 0. And, to me, that doesn't at all seem empty :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: NULLS vs Empty result in PHP
if it can take only numeric values u can use is_numeric() also i suggest that you not to use nulls in dbs. instead, use not null and default value property. Its more simple and more effective for both managing your database and coding your program. -Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Wednesday, September 23, 2009 4:28 PM To: Ralph Deffke Cc: php-general@lists.php.net Subject: Re: [PHP] Re: NULLS vs Empty result in PHP Ralph Deffke wrote: using empty() is ´the right way to check a var for NULL or Empty will also match a string containing 0. And, to me, that doesn't at all seem empty :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Bu mesaj ve ekleri, mesajda gönderildiği belirtilen kişi/kişilere özeldir ve gizlidir. Size yanlışlıkla ulaşmışsa lütfen gönderen kisiyi bilgilendiriniz ve mesajı sisteminizden siliniz. Mesaj ve eklerinin içeriği ile ilgili olarak şirketimizin herhangi bir hukuki sorumluluğu bulunmamaktadır. Şirketimiz mesajın ve bilgilerinin size değişikliğe uğrayarak veya geç ulaşmasından, bütünlüğünün ve gizliliğinin korunamamasından, virüs içermesinden ve bilgisayar sisteminize verebileceği herhangi bir zarardan sorumlu tutulamaz. This message and attachments are confidential and intended for the individual(s) stated in this message. If you received this message in error, please immediately notify the sender and delete it from your system. Our company has no legal responsibility for the contents of the message and its attachments. Our company shall have no liability for any changes or late receiving, loss of integrity and confidentiality, viruses and any damages caused in anyway to your computer system.
RE: [PHP] Re: NULLS vs Empty result in PHP
On Wed, 2009-09-23 at 16:34 +0300, Mert Oztekin wrote: if it can take only numeric values u can use is_numeric() also i suggest that you not to use nulls in dbs. instead, use not null and default value property. Its more simple and more effective for both managing your database and coding your program. -Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Wednesday, September 23, 2009 4:28 PM To: Ralph Deffke Cc: php-general@lists.php.net Subject: Re: [PHP] Re: NULLS vs Empty result in PHP Ralph Deffke wrote: using empty() is ´the right way to check a var for NULL or Empty will also match a string containing 0. And, to me, that doesn't at all seem empty :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Bu mesaj ve ekleri, mesajda gönderildiği belirtilen kişi/kişilere özeldir ve gizlidir. Size yanlışlıkla ulaşmışsa lütfen gönderen kisiyi bilgilendiriniz ve mesajı sisteminizden siliniz. Mesaj ve eklerinin içeriği ile ilgili olarak şirketimizin herhangi bir hukuki sorumluluğu bulunmamaktadır. Şirketimiz mesajın ve bilgilerinin size değişikliğe uğrayarak veya geç ulaşmasından, bütünlüğünün ve gizliliğinin korunamamasından, virüs içermesinden ve bilgisayar sisteminize verebileceği herhangi bir zarardan sorumlu tutulamaz. This message and attachments are confidential and intended for the individual(s) stated in this message. If you received this message in error, please immediately notify the sender and delete it from your system. Our company has no legal responsibility for the contents of the message and its attachments. Our company shall have no liability for any changes or late receiving, loss of integrity and confidentiality, viruses and any damages caused in anyway to your computer system. Or you could leave the database with the nulls in, and cast the value explicitly as an integer with intval() or floatval() which will always give you a numeric value. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php