dongyi6668 2018-10-17 22:04
浏览 39

使用CodeIgniter的变量查询

Hello community I have an issue working on my project and I'm searching for help and a way to solve it. I hope someone of you could help me to achieve that. Thanks for your help.

Background: I'm working on PHP framework Codeigniter v3. I show information from MySQL DB on Data Tables.

ISSUE I want to show a JOIN QUERY info on one Data Table but the information that shows has to be diferent depending on which option the user select.

CONTROLLER 1 (This controller displays all "formulas" in the sistem on one Data Table. What I want to do is when user CLICKS on the first button (onclick="mostrar('."'".$ALIAS_MODEL->id_formula."'".')") that the view changes to another view where there will display a new Data Table with THE CONTENT of the "formula" clicked...) I want to say that I don't have any problem with the first Data Table.

function to fill the formulas's table

    foreach ($list as $ALIAS_MODEL) 
    {
        $row = array();
        $row[] = $ALIAS_MODEL->id_formula;
        $row[] = $ALIAS_MODEL->nombre_formula;

        $row[] = '<a class="btn btn-round btn-info btn-icon btn-sm edit" href="contenidoFormula"  onclick="mostrar('."'".$ALIAS_MODEL->id_formula."'".')"><i class="fas fa-search-plus"></i></a>
        <a class="btn btn-round btn-warning btn-icon btn-sm edit" href="javascript:void(0)"  onclick="edit_formula('."'".$ALIAS_MODEL->id_formula."'".')"><i class="far fa-edit"></i></a>
        <a class="btn btn-round btn-danger btn-icon btn-sm remove" href="javascript:void(0)"  onclick="delete_formula('."'".$FORMULA->id_formula."'".')"><i class="fas fa-times"></i></a>';

        $data[] = $row;
    }
    some code for printing data...
}

CONTROLLER 2

function to fill the content formulas's table
    foreach ($list as $ALIAS_MODEL_TWO) 
    {
        $no++;
        $row = array();
        //$row[] = $no;
        $row[] = $ALIAS_MODEL_TWO->nombre_formula;
        $row[] = $ALIAS_MODEL_TWO->descripcion_material;
        $row[] = $ALIAS_MODEL_TWO->unidad_material;
        $row[] = $ALIAS_MODEL_TWO->costo_material;

        $row[] = '
        <a class="btn btn-round btn-danger btn-icon btn-sm remove" href="javascript:void(0)"  onclick="llenarContenido()"><i class="fas fa-times"></i></a>';

        $data[] = $row;
    }
    some code for printing data...
}

MODEL This model's functions is call to fill the Data Table

private function _get_content($id_formula)
{
    $this->db->select('nombre_formula,descripcion_material,unidad_material,costo_material,porcentaje_formula,tiempo_proceso,porcentaje_agua_bomba,gramos_por_aplicacion,observaciones_detalle_formula');
    $this->db->from('formulas');
    $this->db->join('detalle_formula', 'formulas.id_formula = detalle_formula.id_formula');
    $this->db->join('materiales', 'detalle_formula.id_material = materiales.id_material');
    $this->db->where(array('formulas.id_formula' => $id_formula));

    some extra code here to print data...
}

I want that the variable $id_formula changes its value depending on wich option users clicks

JS Script

function mostrar(id_formula) 
{
  //alert(id_formula);
  return id_formula;
}

$(document).ready(function() 
{
    table = $('#tableName').DataTable({ 
"processing": true, 
"serverSide": true,

 //Carga la informacion desde el archivo AJAX
 "ajax": {
 "url": base_url + "CONTROLLER/FUNCTION/"+id_formula,
 "type": "POST"
  },
});
});

VIEW

...html code
<table id="tableName" class="table table-striped table-bordered" cellspacing="0" width="100%">
    <thead>
      <tr>
        columns...
      </tr>
    </thead>
    <tfoot>
      <tr>
        columns...
      </tr>
    </tfoot>
    <tbody>

    </tbody>
  </table>
html code...
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多