Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在codeigniter中从不同的数据库(或模型)中获取多个值?_Javascript_Sql_Model View Controller_Codeigniter 3 - Fatal编程技术网

Javascript 如何在codeigniter中从不同的数据库(或模型)中获取多个值?

Javascript 如何在codeigniter中从不同的数据库(或模型)中获取多个值?,javascript,sql,model-view-controller,codeigniter-3,Javascript,Sql,Model View Controller,Codeigniter 3,我有3张桌子如下 实验\u表 身份证 方法 结果loq_值最小值clb_值最大值clb_值 标准偏差 项目表 列表项 身份证 实验id 相关表格 抽样法 注册值 样本表 抽样法 相关表格 在samples_table中选择sampling_method和相关_table时,我想自动创建这个表格 到期日| id |方法| |结果| |标准|偏差| reg |值 首先,使用samples_table.related_table和sampling_method从items table中获取实验_id,

我有3张桌子如下

实验\u表

  • 身份证
  • 方法
  • 结果loq_值最小值clb_值最大值clb_值
  • 标准偏差
  • 项目表

  • 列表项
  • 身份证
  • 实验id
  • 相关表格
  • 抽样法
  • 注册值
  • 样本表

  • 抽样法
  • 相关表格
  • 在samples_table中选择sampling_method和相关_table时,我想自动创建这个表格

    到期日| id |方法| |结果| |标准|偏差| reg |值

    首先,使用samples_table.related_table和sampling_method从items table中获取实验_id,并在该表中填充实验_id和reg_值

    然后,从实验表中获取其他参数(方法、结果和标准偏差),并在第一步从项目表中找到实验id

    如何在codeigniter 3中实现这一点?请给我一个建议(视图、模态形式、模型和控制器)

    这是my model->sample\u items\u model.php

       function get_item_suggestion($keyword = "") {
        $experiments_table = $this->db->dbprefix('experiments');
    
        $sql = "SELECT $experiments_table.title
        FROM $experiments_table
        WHERE $experiments_table.deleted=0 AND $experiments_table.title LIKE '%$keyword%'
        LIMIT 30 
       ";       
        return $this->db->query($sql)->result();
    }
    
    function get_item_info_suggestion($item_name = "") {
    
        $experiments_table = $this->db->dbprefix('experiments');
    
    
        $sql = "SELECT $experiments_table.*
        FROM $experiments_table
        WHERE $experiments_table.deleted=0  AND $experiments_table.title LIKE '%$item_name%'
        ORDER BY id DESC LIMIT 1
        ";
    
        $result = $this->db->query($sql); 
    
        if ($result->num_rows()) {
            return $result->row();
        }
    
    }
    
    这是我的控制器->samples.php

       /* prepare suggestion of sample item     */
    
    function get_sample_item_suggestion() {
        $key = $_REQUEST["q"];
        $suggestion = array();
    
        $items = $this->Sample_items_model->get_item_suggestion($key);
    
        foreach ($items as $item) {
            $suggestion[] = array("id" => $item->title, "text" => $item->title);
        }
    
        $suggestion[] = array("id" => "+", "text" => "+ " . lang("create_new_item"));
    
        echo json_encode($suggestion);
    }   
    
    
    function get_sample_item_info_suggestion() {
        $item = $this->Sample_items_model->get_item_info_suggestion($this->input->post("item_name"));
        if ($item) {
            echo json_encode(array("success" => true, "item_info" => $item));
        } else {
            echo json_encode(array("success" => false));
        }
    }
    
    这是我的modal_form脚本->item_modal_form.php

        function applySelect2OnItemTitle() {
        $("#sample_item_title").select2({
            showSearchBox: true,
            ajax: {
                url: "<?php echo get_uri("samples/get_sample_item_suggestion"); ?>",
                dataType: 'json',
                quietMillis: 250,
                data: function (term, page) {
                    return {
                        q: term // search term
                    };
                },
                results: function (data, page) {
                    return {results: data};
                }
            }
        }).change(function (e) {
            if (e.val === "+") {
                //show simple textbox to input the new item
                $("#sample_item_title").select2("destroy").val("").focus();
                $("#add_new_item_to_library").val(1); //set the flag to add new item in library
            } else if (e.val) {
                //get existing item info
                $("#add_new_item_to_library").val(""); //reset the flag to add new item in library
                $.ajax({
                    url: "<?php echo get_uri("samples/get_sample_item_info_suggestion"); ?>",
                    data: {item_name: e.val},
                    cache: false,
                    type: 'POST',
                    dataType: "json",
                    success: function (response) {
    
                        //auto fill the method, unit type and rate fields.
                        if (response && response.success) {
    
                            if (!$("#sample_item_method").val()) {
                                $("#sample_item_method").val(response.item_info.method);
                            }
    
                            if (!$("#sample_conc_type").val()) {
                                $("#sample_conc_type").val(response.item_info.conc_type);
                            }
    
                            if (!$("#sample_item_result").val()) {
                                $("#sample_item_result").val(response.item_info.result);
                            }
    
                            if (!$("#sample_item_loq_value").val()) {
                                $("#sample_item_loq_value").val(response.item_info.loq_value);
                            }
    
                            if (!$("#sample_item_min_clb_value").val()) {
                                $("#sample_item_min_clb_value").val(response.item_info.min_clb_value);
                            }
    
                            if (!$("#sample_item_max_clb_value").val()) {
                                $("#sample_item_max_clb_value").val(response.item_info.max_clb_value);
                            }
    
                            if (!$("#sample_item_std_deviation").val()) {
                                $("#sample_item_std_deviation").val(response.item_info.std_deviation);
                            }                           
                        }
                    }
                });
            }
    
        });
    }
    
    函数applySelect2OnItemTitle(){
    $(“#示例#项目#标题”)。选择2({
    showSearchBox:正确,
    阿贾克斯:{
    url:“”,
    数据类型:“json”,
    安静百万:250,
    数据:功能(术语,第页){
    返回{
    q:术语//搜索术语
    };
    },
    结果:功能(数据、页面){
    返回{结果:数据};
    }
    }
    }).更改(功能(e){
    如果(e.val==“+”){
    //显示简单文本框以输入新项目
    $(“#示例#项目#标题”)。选择2(“销毁”).val(“”.focus();
    $(“#添加新项目到库”).val(1);//设置在库中添加新项目的标志
    }否则如果(e.val){
    //获取现有项目信息
    $(“#将#new_item_添加到_库”).val(“”;//重置标志以在库中添加新项
    $.ajax({
    url:“”,
    数据:{item_name:e.val},
    cache:false,
    键入:“POST”,
    数据类型:“json”,
    成功:功能(响应){
    //自动填充方法、单位类型和费率字段。
    if(response&&response.success){
    if(!$(“#示例_项_方法”).val(){
    $(“示例项目方法”).val(response.item信息方法);
    }
    if(!$(“#示例#conc_type”).val()){
    $(“#示例#conc_类型”).val(response.item_info.conc_类型);
    }
    if(!$(“#样本项目_结果”).val(){
    $(“示例项目结果”).val(response.item信息.result);
    }
    if(!$(“#示例#项目_loq_值”).val(){
    $(“#样本#项目(loq)值”).val(response.item(信息)loq(值));
    }
    if(!$(“#示例#项目_最小_clb_值”).val()){
    $(“#示例#项目_最小_clb_值”).val(response.item_info.min_clb_值);
    }
    如果(!$(“#样本#项目_最大_clb_值”).val()){
    $(“#示例#项目_最大_clb_值”).val(response.item_info.max_clb_值);
    }
    如果(!$(“#样品(项目)标准)偏差”).val()){
    $(“样本项目标准偏差”).val(响应项目信息标准偏差);
    }                           
    }
    }
    });
    }
    });
    }