I have CodeIgniter project I'd like to "upgrade" :) In one part of it I'm selecting a value (primary key) from table and displaying all the data from that record. Currently I'm using dropdown menu for selection and a button to start a query which then shows the data on the same page. Table has following fields:
claim_id - primary key
repair_type
type
block
condition
defect
symptom
repair
addition
My Model:
class Claim_m extends MY_Model
{
protected $_table_name = 'claim';
protected $_order_by = 'repair_type';
protected $_primary_key = 'claim_id';
public function __construct()
{
parent::__construct();
}
public $rules_claim = array(
'repair_type'=>array(
'field'=>'claim_id',
'label'=>'ID Claima',
'rules'=>'required'
)
);
public function daj_dropdown() //creates dropdown
{
$rezultat = $this->db->select('claim_id,repair_type')->get('claim')->result_array();
$dropdown = array();
foreach($rezultat as $r)
{
$dropdown[$r['claim_id']] = $r['repair_type'];
}
return $dropdown;
}
}
My Controller:
class Claims extends Frontend_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('claim_m');
}
public function choice()
{
//validation
$rules = $this->claim_m->rules_claim;
$this->form_validation->set_rules($rules);
if($this->form_validation->run() == TRUE)
{
$claim_id = $this->input->post('claim_id');
$this->data['zapisi'] = $this->claim_m->daj($claim_id,TRUE);
}
//dropdown
$this->data['dropdown'] = $this->claim_m->daj_dropdown();
//set subview
$this->data['subview'] = 'claim/zapis';
$this->load->view('_main_layout', $this->data);
}
}
My View (zapis.php):
<?php echo form_open();?>
<table class="table">
<tr>
<td>Type of repair:</td>
<td><?php echo form_dropdown('claim_id',$dropdown); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Izaberi', 'class="btn btn-primary"'); ?></td>
</tr>
</table>
<?php echo form_close(); ?>
<?php
if(!isset($zapisi))
{
echo 'no records';
}
else
{ ?>
<section>
<h2>Claim pattern - <u> <?php echo($zapisi->repair_type); ?> </u></h2>
<i>Defect type: </i><font color="red"><?php echo($zapisi->type); ?></font></br>
<i>Defect block: </i><font color="red"><?php echo($zapisi->block); ?></font></br>
<i>Condition code: </i><font color="red"><?php echo($zapisi->condition); ?></font></br>
<i>Defect code: </i><font color="red"><?php echo($zapisi->defect); ?></font></br>
<i>Symptom code: </i><font color="red"><?php echo($zapisi->symptom); ?></font></br>
<i>Repair code: </i><font color="red"><?php echo($zapisi->repair); ?></font></br>
<i>Other: </i></br><font color="red"><?php echo($zapisi->addition); ?></font></br>
</section>
<?php } ?>
All of this works fine but I need to make it without button on the view. Basically I need to write down all the other fields whenever selection is changed in dropdown menu without need to press button. I've found out about tutorial when one filed is needed but I need to present (after change in dropdown menu) 7 fields from MySQL database table (type, block, condition, defect, symptom, repair, addition).
I don't know much about jQuery or Ajax but I presume its needed for something like this. If somebody can help me with this or point me to the right tutorial I would be grateful. Thank you in advance!
Edit: function daj() from MY_Model
public function daj($id = NULL, $single = FALSE)
{
if ($id != NULL)
{
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->where($this->_primary_key,$id);
$method = 'row';
}
elseif($single == TRUE)
{
$method = 'row';
}
else
{
$method = 'result';
}
$this->db->order_by($this->_order_by);
return $this->db->get($this->_table_name)->$method();
}
Aucun commentaire:
Enregistrer un commentaire