Welcome Guest, Not a member yet? Register   Sign In
Cannot test if a field is empty or not
#11

[eluser]toopay[/eluser]
change the model at the last section
Code:
//if there are a match result, bring first row. Else, Null
//return (count($result) > 0 ? $result[0] : NULL);
//if there are a match result, bring list. Else, Null
return (count($result) > 0 ? $result : NULL);
}
and change your controller
Code:
if(is_null($resultats))
{
//if there are no result, give a warning
echo "No result for'" . $critere . "'. Try another criteria!" ;
}
else
{
//if there are 1 result, test it
//  $data=array();
//  $data['resultats']=$resultats['DIVERS'];
//    if ($data['resultats']=='')
//        {
//            echo "Divers empty<br />";
//    }else{
//            echo "Divers not empty<br />";
//    }
//if there are list of result, test it
$data=array();
$i=count($resultats);
$j=0;
while ($j<$i)
    {
    $data['resultats']=$resultats['DIVERS'];
        if ($data['resultats']=='')
        {
            echo "Divers empty<br />";
        }else{
            echo "Divers not empty<br />";
        }
    j++;
    }

}
#12

[eluser]caperquy[/eluser]
Thanks. I will implement that this afternoon.
Caperquy
#13

[eluser]toopay[/eluser]
Code:
return (count($result) >0 ? $result[0] :NULL);
that means, if the result more than 0, the function return first row matched
Code:
$result[0]
if not, it returns NULL. For an array result, you can just simply change
Code:
$result[0]
to
Code:
$result
at the end of your model function, and write the rest proper code at your controller to handle that array.
#14

[eluser]caperquy[/eluser]
Many thanks for your help. Now it works fine.
Regards
CapErquy




Theme © iAndrew 2016 - Forum software by © MyBB