List <select> has two values!

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 21, 2012   (RSS)

When working with lists in the editor...

Before selecting an item, the default option <select> has a value of NULL

However, if you first select any other item in the list - then save - then select the <select> option again - and save - the value is EMPTY.

This means that <select> effectively has two different values - which can be problematic, as I have just discovered!

:0/

Perchpole

Re: [Perchpole] List <select> has two values!

Hi,

We've done some local testing and we think we've recreated the problem. Have you added the list field after some entries had already been added to the table? We found that creating new entries or modifying old entries put an empty string in the column. But entries that were created before the list field was added had a value of null in that column. Is this the same problem your experiencing?

Also how are you detecting the null value? If it's through a PHP if statement you could use a == instead of is_null() to detect if the field is empty as it treats null and empty strings in the same way.

if($row['list'] == ""){
//This will treat both null and an empty string as true
}
if(is_null($row['list'])){
//This will only be true for values of null.
}


If you are detecting null through a MySQL WHERE statement then the solution would be to use a where statement similar to this:

WHERE ( testlist IS NULL OR testlist = '' )

Thanks!

Greg
Greg Thomas







PHP Programmer - interactivetools.com