codeigniter 3 where子句无法正常工作

e0uiprwp  于 2023-03-16  发布在  其他
关注(0)|答案(1)|浏览(141)

我尝试在CodeIgniter 3中构建查询,奇怪的是当我传递变量时WHERE子句显示IS NULL
这是我的密码

我的视图代码

<?php echo form_open('Access/show'); ?>
                        <div class="form-group">
                            <div class="my-3">
                                <label class="form-label" for="startdate">Dooro Taariikh:</label>
                                <input type="date" class="form-control" value="" name="whichday" id="whichday" required="required">
                            </div> 
                        </div>
                        <div class="form-group">
                            <div class="my-3">
                                <label class="form-label" for="MobileNo">MobileNo:</label>
                                <input type="number" name="phone" placeholder="25263XXXXXXX" id="MobileNo" class="form-control" required="required">
                            </div> 
                        </div>
                                                    
                        <div class="form-group my-3">
                            <input type="submit" class="au-btn au-btn--block au-btn--green form-control rounded" value="submit" name="showChannel">
                        </div>
                   
             <?php echo form_close(); ?>

我的控制器代码

public function show(){
        if ($this->session->userdata('isUserLoggedIn')) {
            $this->load->view('incl/header');
            $this->load->view('incl/sidebar');
            $this->load->view('incl/navbar');
            $this->load->view('dash/access/view');
            $this->load->view('incl/datatable');
           
        } else {
            $this->load->view('incl/header');
            $this->load->view('login');
            $this->load->view('incl/script');
        }
    }

    public function getAccess(){

        $phone = $this->input->post('phone');
        $data = $this->AccessChannel->showAccess($phone); 
        echo json_encode($data);  

    }

我的型号代码

public function showAccess($phone)
    {
        $this->db->select('createdat, SenderMobile,ReceiverMobile,transferid,Currency,ChannelName,shortCodeDailed');
        $this->db->from('loggingprofile2');

        $this->db->where('SenderMobile =',$phone);
        $query = $this->db->get();
        var_dump($this->db->last_query());
        // die();
        return $query->result();

我希望where条件首先运行,因为它在sql查询中,但where条件返回NULL。
字符串(164)“从loggingprofile2中选择createdatSenderMobileReceiverMobiletransferidCurrencyChannelNameshortCodeDailed,其中senderMobile为空”
致命错误:第59行上的/var/www/html/accest/application/controllers/Access. php中允许的134217728字节内存大小已用尽(尝试分配10489856字节)

shyt4zoc

shyt4zoc1#

用途

$this->db->where('SenderMobile',$phone);

代替

$this->db->where('SenderMobile =',$phone);

或者另一种更简单的方法

$sql = "SELECT createdat, SenderMobile, ReceiverMobile, transferid, Currency, ChannelName, shortCodeDailed FROM loggingprofile2 WHERE senderMobile = " . $phone;
$res = $this->db->query($sql)->result_array();

相关问题