【问题标题】:I can't select data using where clause when imported from excel in Codeigniter从 Codeigniter 中的 excel 导入时,我无法使用 where 子句选择数据
【发布时间】:2015-06-24 06:53:12
【问题描述】:

在我导入Excell 到 DB 之后,我尝试从 DB 中选择我的数据,如下代码

问题如果我复制 In_no 值 (isp14065556) 并传递到文本编辑器并传递回表中的 in_no,那么我的 select by where 也会起作用。为什么?

我的 In_no 类型的表是 varchar(30),我使用 In_no 作为 Where 子句

问题如果我通过键入插入 in_no 字符串值,我可以通过 where 选择,如果 In_no 字符串值,我无法通过 where 选择从 Excel 中导入(in_no 内容存储在 Excel 中并导入到 Db)。

我不明白为什么,因为 in_no 类型是 varchar(30) 并且我在使用 Where 子句选择数据方面有更多经验来自 DB 很多次。但是这个我真的不明白为什么我从excel导入数据时无法选择数据。

public function printds(){
        $segment = $this->uri->segment(3);
        $this->db->select('*');
        $this->db->from('dbfinan_dupl_invoice');
        $this->db->where('in_no',$segment);//tested arary('in_no'=>$segment)
        $query = $this->db->get();
        return $query->result();
    }

在控制器中

public function printd(){

        $segment = $this->uri->segment(3);
        $this->data['invoice_val'] = $this->invoice_m->select_ad_val($segment);
        $this->data['print_item'] = $this->invoice_m->printds($segment);
        $this->load->view('frontend/print/print_dup',$this->data);
    }

非常感谢朋友的好意

【问题讨论】:

  • 您是否遇到任何错误? $segment 的值是多少?
  • $segment = $this->uri->segment(3);我将它从控制器传递给模型
  • @Uchiha 我不明白当我通过键入它的值在 DB 中编辑 In_no 时它会起作用。但它无法选择我是否使用 where 子句和从 Excel 导入的 in_no 值。为什么因为它也是字符串
  • 尝试使用echo $this->db->last_query();并在sql中发布该查询并检查它是否在那里工作
  • 有效吗?你在sql里面试过了吗

标签: php mysql sql-server excel codeigniter


【解决方案1】:

请使用此代码

    $segment = $this->uri->segment(3);
    $data['invoice_val'] = $this->invoice_m->select_ad_val($segment);
    $data['print_item'] = $this->invoice_m->printds($segment);
    $this->load->view('frontend/print/print_dup',$this->data);

【讨论】:

  • 和以前一样。我担心我在 DB 中的行中的 in_no 字符串,如果我将 in_no 内容编辑为新字符串,它就会起作用。那么这个case是不是In_no类型或者sql字符串的问题呢?
  • 问题如果我复制 In_no 值 (isp14065556) 并传递到文本编辑器并复制它,然后将其传递回表中的 in_no 中,我选择的位置也可以。为什么?
【解决方案2】:

@宇智波 @阿卜杜拉 现在我找到了解决方案感到非常高兴

'in_no' =>  strtolower(trim(preg_replace("/(\D+\d{4})0*([1-9]+\d*)/i", "$1$2\n", strtolower($data['IN_number'])))),

我没有清理 in_no 但是在我使用 strtolowertrim 之后,它就完美了 感谢朋友的一些想法

【讨论】:

    猜你喜欢
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2021-07-31
    • 2016-04-21
    • 1970-01-01
    相关资源
    最近更新 更多