Adsense
Popular Posts
- Install APXS in Redhat Linux
- MySQL workbench -"Could not decrypt password cache"
- Transfer modules between sites
- JavaScript, remove trailing insignificant zeros after toFixed function
- Set Windows path command line
- datatable order by nunmeric
- MySQL date created and date modified
- super(props) in React
- PHP, dump varailbes in a format way
- React: connect(mapStateToProps, mapDispatchToProps)
Tuesday, November 15, 2016
PHP null compare to 0
When PHP gets null from MySQL NULL column and compare to 0
$ChairRecomStep_arr = array(0,0.5,1,1.5,2);
$AdditionStepOrder = $AdditionStepOrder.'</select>';
$ChairRecomStep = '<select name="ChairRecomStep" class="ChairRecomStep"><option value="">Select</option>';
foreach($ChairRecomStep_arr as $row0){
$select=' ';
if($row['ChairRecomStep']== $row0) $select='selected';
$ChairRecomStep = $ChairRecomStep.'<option value="'.$row0.'" '.$select.'>'.
$row0.'</option> ';
}
$ChairRecomStep = $ChairRecomStep.'</select>';
In this code, null compare to 0 is true, the select dropdwon pickup 0 value instead of empty.
To make null compare to 0 is false, we should use = = =
if($row['ChairRecomStep']=== $row0)
Also when we use empty function in PHP, the 0 also treated as empty. To avoid 0 treated as empty:
if(empty($ChairRecomStep) && $ChairRecomStep!=0) $ChairRecomStep=null;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment