Reputation: 169
I just want to ask how can you get the value of the texbox in this code:
Here is my view:
<div class="row">
<h3><input type='text' name="table1" value='<?php echo $table1; ?>' style='border: none; background-color: transparent;' readonly/></h3>
<div class="table_design">
<button style='position: absolute; top:290px; right: 173px;' class='btn_addinventory btn-success btn-sm' id='btn_addinventory' name='btn_addinventory'><span class='glyphicon glyphicon-plus'></span> Add Inventory</button>
<table class="boom_table">
<tr>
<?php foreach($sample1 as $field) { ?>
<th><?php echo $field->name; ?></th>
<?php } ?>
</tr>
<?php foreach($select1 as $row) { ?>
<tr>
<td><?php echo $row->ID; ?></td>
</tr>
<?php } ?>
</table>
<?php foreach($sample1 as $field) { ?>
<input type="text" name="txt_rowname" value="<?php echo $field->name; ?>"/>
<?php } ?>
</div>
</div>
Here is the controller:
public function inventory_new(){
$tablenaming1 = $_POST['ninja7'];
// var_dump($tablenaming1);
// exit;
$this->session->userdata('login_session');
$this->data['title'] = "Inventory";
$this->load->vars($this->data);
$this->load->view('homeview');
$select_inv['inventorytype'] = $this->inventory_model->select_tables();
$this->load->view('inventoryview', $select_inv);
$sample['sample'] = $this->inventory_model->select_fields_2($_POST['ninja7']);
$select_details['select'] = $this->inventory_model->select_queries2($this->input->post());
// var_dump($select_details);
// exit;
$value_array = array('sample1' => $sample['sample'],
'table1' => $tablenaming1,
'select1' => $select_details['select']);
$this->load->view('sampleviewtable', $value_array);
$this->load->view('footer_view');
}
And here is my model:
public function select_fields_2($tablename2){
$fields = $this->db->field_data($tablename2);
return $fields;
}
public function select_queries2($tablename){
$select_table = $this->db->select('*')
->from($tablename['ninja7']);
return $select_table->get()->result();
}
In my view above you will see:
<?php foreach($select1 as $row) { ?>
<tr>
<td><?php echo $row->ID; ?></td>
</tr>
<?php } ?>
And this:
<?php foreach($sample1 as $field) { ?>
<input type="text" name="txt_rowname" value="<?php echo $field->name; ?>"/>
<?php } ?>
I want to get the value of the <input type="text" name="txt_rowname" value="<?php echo $field->name; ?>"/>
from my view, For example: if the value of this textbox is equal to 'Name' instead of $row->ID
now it should be $row->Name
. I really can't figure out this yet, I want to pass the value of the textbox instead of putting 'ID' on $row. Is there a way to do that?
Thank you in advance for your help! :)
Upvotes: 0
Views: 3507
Reputation: 801
Eljon as per your comments and what i understand your requirement is you need to populate table structure on clicking table name.
So,in codeigniter their is a simple way to achieve this like this:
$fields = $this->db->list_fields('table_name');
foreach ($fields as $field)
{
echo $field;
}
Here 'list_fields' will give you your fields name of specified table.
If you want to get field data you can try this out :
$fields = $this->db->field_data('table_name');
foreach ($fields as $field)
{
echo $field->name;
echo $field->type;
echo $field->max_length;
echo $field->primary_key;
}
Here is more information in codeigniter documentation https://ellislab.com/codeigniter/user-guide/database/fields.html
Hope this helps you.
Regards, Zeeshan.
----- Update ------ You can populate database table in tabular structure using inbuilt codeigniter library,you can directly echo that table in your view the code goes like this:
$this->load->library('table');
$query = $this->db->get('table_name');
$page_data['db_table'] = $this->table->generate($query);
In your view :
echo $db_table
--- Update 2 ---- Update as per your comments and requirements
you can use set_template of table class to set the id as
$tmpl = array ( 'table_open' => '<table id="YOUR_ID" class="mytable">' );
$this->table->set_template($tmpl);
More details regarding table class here https://ellislab.com/codeigniter/user-guide/libraries/table.html
Upvotes: 1