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

(This post was last modified: 04-09-2016, 08:03 AM by spjonez.)

Couple options;

1. Validate the record before you try to access it. We do that like this;

Code:
$result = $this->db->query( $sql, $params )->row_array( );

if ( empty( $result ) === true ) {
    // set flash data saying row not found
    // redirect to another page
}

2. If you're using a combined create/edit page ensure the array always has keys by merging it with a set of defaults.

Code:
$defaults = array(
    'id' => 0,
    'name' => '',
);

$result = $this->db->query( $sql, $params )->row_array( );

$result = array_merge( $defaults, $result );
Reply


Messages In This Thread
RE: Forms displaying error if no result is found. - by spjonez - 04-09-2016, 08:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB