Welcome Guest, Not a member yet? Register   Sign In
Forms displaying error if no result is found.
#1

I have this codes like this in my controller. It works fine. But when there is no record found in the database, it display a lot of errors because of $customer[0]->first_name.

$data['bfname'] = array(
'name' => 'bfname',
'id' => 'bfname',
'class' => 'form-control',
'type' => 'text',
'value' => $this->form_validation->set_value('bfname', $customer[0]->first_name),
);

I'm thinking of solving it by:

if ($customer) {
$bfname = $customer[0]->first_name;
}
else {
$bfname = '';
}

Then I'll put the $bfname in the value. But is there another way of solving this in CI?
Reply


Messages In This Thread
Forms displaying error if no result is found. - by mydiskarte - 04-06-2016, 10:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB