[eluser]IFR70[/eluser]
Hi all,
I'm a beginner in PHP and Codeigniter, so please apologize if my question is very basic.
I have two tables like these:
The first table name is "friends" and the columns are:
- ID_friend (int)
- Name (varchar(50))
- Surname (varchar(50))
- ID_nation (int)
The second table is "nation" and the columns are:
- ID_nation (int)
- Nation_name (varchar(50))
OK, now I have to build a form to insert a record on the table "friends", but I want to decode the field "ID_nation" with all the "Nation_name"s of the second table.
In my model I have this function:
Code:
function listColumns()
{
$fields = $this->db->field_data($this->table);
return $fields;
}
The array returned by this function is this one:
Code:
Array
(
[0] => stdClass Object
(
[name] => ID_friend
[type] => int
[default] =>
[max_length] => 11
[primary_key] => 1
)
[1] => stdClass Object
(
[name] => Name
[type] => varchar
[default] =>
[max_length] => 50
[primary_key] => 0
)
[2] => stdClass Object
(
[name] => Surname
[type] => varchar
[default] =>
[max_length] => 50
[primary_key] => 0
)
[3] => stdClass Object
(
[name] => ID_nation
[type] => int
[default] => 0
[max_length] => 11
[primary_key] => 0
)
)
Is there a smart way to substitute ID_nation with the list of the nations in the second table, so when I pass the array to the view I can easily build an HTML SELECT?
Cheers.