php - Passing data from View to Controller for sql statement in Model in CI -
hi have simple form of images user can click on , depending on image clicked on modal dialog appear list of data database. have working 1 whereby state specific column name in mysql statement not via variable. able know how/where pass value of image input view controller can used in mysql statement in view..i pass mysql statement controller model view. below code. appreciated brand new ci , abit confused.thanks!
controller:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class app extends my_controller { function __construct() { parent::__construct(); log_message('debug', 'app controller has been initialized'); } public function toolsmodal() { $dept = $this->input->post('submit'); //echo $dept; $this->load->model('tools_model'); $tools = $this->tools_model->gettools($dept); $data['tools'] = $tools; $data['view'] = 'datatables'; $this->load->view('templates/default', $data); } public function index() { $data['view'] = 'datatables'; $this->load->view('templates/default', $data); } public function welcome() { $data['view'] = 'welcome'; $this->load->view('templates/default', $data); } public function datatables() { // can safely delete method. example. $data['view'] = 'datatables'; $this->load->view('templates/default', $data); } }
model:
class tools_model extends ci_model { public function gettools($dept) { //$query = $this->db->query("select rname,decription,dri,developer, golive web.reportdash applestore = 'yes'"); $this->db->select('rname, decription, dri, developer, golive'); $this->db->where($dept, 'yes'); $query = $this->db->get('web.reportdash'); $tools = array(); foreach ($query->result() $row) { $tools[] = $row; } return $tools; }
} ?>
view:
<table> <tr> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-applestore' src="<? echo base_url("/_assets/img/store.png"); ?>" name='submit' value='store'> <br>applestore</td> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"> <input type='image' id='filters-trigger-storef' src="<? echo base_url("/_assets/img/finance.png"); ?>" name='submit' value='finance'><br>finance</td> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storel' src="<? echo base_url("/_assets/img/logistics.png"); ?>" name='submit' value='logistics'> <br>logistics</td> </tr> <tr></tr> <tr> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storeman' src="<? echo base_url("/_assets/img/manufacturing.jpg"); ?>" name='submit' value='manufacturing'><br>manufacturing</td> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storect' src="<? echo base_url("/_assets/img/control.jpg"); ?>" name='submit' value='controltower'><br>control tower</td> <td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storeom' src="<? echo base_url("/_assets/img/om.jpg"); ?>" name='submit' value='ordermanagement'><br>order management</td> </tr>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"> <input type='image' id='filters-trigger-stores' src="<? echo base_url("/_assets/img/sales.jpg"); ?>" name='submit' value='sales'><br>sales</td> </tr> </table> </form> </div> <div class="container"> <div class="filters-trigger-applestorem not-displayed modal1 hide fade in" style="overflow:auto;"> <button type="button" id='close' class="close" data-dismiss="filters-trigger-applestorem">×</button> <table class="table table-bordered smaller-font margin-top-medium" style="margin: 0;"> <thead> <tr> <td>report name</td> <td>description</td> <td>dri</td> <td>developer</td> </tr> </thead> <tbody> <?php foreach($tools $tool): ?> <tr class="padding-larger-right table-header"><td><?= $tool->rname; ?> </td> <td class="smaller-padding vertical-centred"><?= $tool->decription; ?></td> <td class="smaller-padding vertical-centred"><?= $tool->dri; ?></td> <td class="smaller-padding vertical-centred"><?= $tool->developer; ?></td> <?php endforeach ?> </tbody> </table> </div>
hi modify model, loop in model $tool array have last row every time on write old array here modified
class tools_model extends ci_model { public function gettools($dept) { //$query = $this->db->query("select rname,decription,dri,developer, golive web.reportdash applestore = 'yes'"); $this->db->select('rname, decription, dri, developer, golive'); $this->db->where($dept, 'yes'); $query = $this->db->get('web.reportdash'); return $query->result(); } } ?>
you can loop in view now
Comments
Post a Comment