Welcome Guest, Not a member yet? Register   Sign In
Problem creating a 2-D array from table details
#1

[eluser]alwaystyred[/eluser]
Hi, I am trying to create a 2-D array containing details of the tables and the fields within those tables. This is the code in my controller:
Code:
$this->view_data['tables'] = $this->db->list_tables();
foreach ($this->view_data['tables'] as $table) {
$this->view_data['tables']['fields'] = $this->db->list_fields($table);
}

This works fine for the tables, I am able to get all of those in the view, but it only returns the field details of the last table it queries.

The code in the view is:
Code:
foreach ($tables as $table) {
echo '<p class="head">' .$table . '</p>';

echo '<div class="body">';
foreach ($tables['fields'] as $field) {
  echo '&lt;input type="checkbox" name="field" value="' . $table . '.' . $field .'" /&gt;' . $field . '<br />';
}
echo '</div>';
}

Thanks for help in advance, if you need more info, I'm happy to provide
#2

[eluser]alwaystyred[/eluser]
I have found that I can do this in the view using the following code:

Code:
$tables = $this->db->list_tables();
echo '<div class="table_details">';
foreach ($tables as $table) {
echo '<p class="table_name">' .$table . '</p>';
$fields = $this->db->list_fields($table);
echo '<div class="fields">';
$fields = $this->db->list_fields($table);
foreach ($fields as $field) {
  echo $field . '<br>';
}
echo '</div>';
}
echo '</div>';

Would this be considered poor form as I thought all logic should be contained within the controller, or is this a suitable workaround?
#3

[eluser]Near[/eluser]
Try this
Code:
$this->view_data['tables'][] = $this->db->list_fields($table)

im not sure if that is the solution to your proble..




Theme © iAndrew 2016 - Forum software by © MyBB