Welcome Guest, Not a member yet? Register   Sign In
how to handle a sql retrieve and form request at best
#1

[eluser]zenon[/eluser]
I wonder, what could be the best way to:

1-get a result from db
2-put result in input form

Using form helper, I build an input text in this way:
Code:
$data = array(
    'name' => 'username',
    'id' => 'username',
    'value' => $user_info[0]->name,
    'maxlength' => '100',
    'size' => '50',
    'style' => 'width:50%',
);

but if user_info return no record, code will result in error.
It might be useful to always initialize user_info with 1 empty result, but I wonder if there's a better way.

Any suggestions?

PS
I would like to use smarty template and I got the code from coolphp site but I've noticed some bugs.
Anyone here's knows other parser template engine easily integratables with CI ?
(I tried internal CI parser but I would like to use something more powerful)
#2

[eluser]SitesByJoe[/eluser]
You should use a little logic while building your array like this:

Code:
$data = array(
    'name' => 'username',
    'id' => 'username',
    'value' => (isset($user_info[0]->name)) ? $user_info[0]->name : '',
    'maxlength' => '100',
    'size' => '50',
    'style' => 'width:50%',
);

That way there's no error if the value isn't set.

You could even be more clever than that and:

Code:
$data = array(
    'name' => 'username',
    'id' => 'username',
    'value' => (isset($user_info[0]->name)) ? $user_info[0]->name : set_value('username'),
    'maxlength' => '100',
    'size' => '50',
    'style' => 'width:50%',
);




Theme © iAndrew 2016 - Forum software by © MyBB