您好我有一个简单的图像形式,用户可以点击它,根据点击模态对话框的图像,将显示数据库中的数据列表。我有一个工作,我在mysql语句中不通过变量声明特定的列名称。我想知道如何/在哪里我将图像输入的值从视图传递给控制器,以便它可以在视图中的mysql语句中使用..我已经从控制器传递mysql语句到模型到视图。以下是我的代码。任何帮助将不胜感激,因为我是CI的新手并且abit confused.Thanks!
控制器:
<?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()
{
// You can safely delete this method. It is an 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 from web.reportdash where 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() as $row) {
$tools[] = $row;
}
return $tools;
}
} ?&GT;
查看:
<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 as $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>
答案 0 :(得分:0)
嗨,只需修改你的模型,对于模型中的循环$ tool数组在每次写入旧数组时都会只有最后一行是你的修改
class Tools_model extends CI_Model
{
public function getTools($Dept)
{
//$query = $this->db->query("select rname,decription,DRI,developer, golive from web.reportdash where AppleStore = 'Yes'");
$this->db->select('rname, decription, DRI, developer, golive');
$this->db->where($Dept, 'Yes');
$query = $this->db->get('web.reportdash');
return $query->result();
}
} ?>
您现在可以轻松循环播放