dsfbnhc4373 2013-05-08 17:36
浏览 92

将数据从View传递到Controller,用于CI中的Model中的sql语句

Hi I have a simple form of images that a user can click on and depending on the image clicked on a modal dialog will appear with a list of data from the database. I have this working for one whereby I state the specific column name in the mysql statement not via a variable. I would like to be able to know how/where I pass the value of the image input from the view to the controller so that it can be used in the mysql statement in the view..I already pass the mysql statement from the controller to the model to the view. Below is my code. Any help would be appreciated as I am brand new to CI and 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()
{
    // 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;
}

} ?>

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 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>

  • 写回答

1条回答 默认 最新

  • dongque1462 2013-05-08 18:03
    关注

    hi just modify your model, for loop in model $tool array will always have only last row every time its over write old array here is your modified

        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();
    
    }
    
    } ?>
    

    you can easily loop in view now

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?