【问题标题】:how to create table from codeigniter-query?如何从 codeigniter-query 创建表?
【发布时间】:2019-08-17 19:37:59
【问题描述】:

我想从以下查询创建一个表...

背景是,我制作了一个额外的表格来搜索有关每个俱乐部的详细信息,您可以在其中搜索俱乐部名称的单个详细信息,或者您可以组合俱乐部名称的部分字段,让我们说部分街道名称,但表中的某些字段可以为 NULL。所以我实现了这些 IF ELSE 和 LIKE 语句。这工作正常,但如何将这些 $query 放入表中,如 CREATE TABLE SearchedClubs AS (SELECT * FROM Clubs WHERE...)

$this->db->select('*');
$this->db->from('Clubs');
if ($clubname <> NULL) {
    $this->db->like('Clubname', $clubname, 'both'); }
if ($street <> NULL) { 
    $this->db->like('Street', $street, 'both'); }
if ($postalcode <> NULL) { 
    $this->db->like('Postalcode', $postalcode, 'both'); }
if ($city <> NULL) { 
    $this->db->like('City', $city, 'both'); }
if ($homepage <> NULL) { 
    $this->db->like('Homepage', $homepage, 'both'); }
if ($email <> NULL) { 
    $this->db->like('Email', $email, 'both'); }
if ($telephone <> NULL) { 
    $this->db->like('Telephone', $telephone, 'both'); }   
$query = $this->db->get();

【问题讨论】:

    标签: php mysql codeigniter-3 create-table


    【解决方案1】:

    简单的方法是

    $this->db->select('*');
    $this->db->from('Clubs');
    if ($clubname <> NULL) {
        $this->db->like('Clubname', $clubname, 'both'); }
    if ($street <> NULL) { 
        $this->db->like('Street', $street, 'both'); }
    if ($postalcode <> NULL) { 
        $this->db->like('Postalcode', $postalcode, 'both'); }
    if ($city <> NULL) { 
        $this->db->like('City', $city, 'both'); }
    if ($homepage <> NULL) { 
        $this->db->like('Homepage', $homepage, 'both'); }
    if ($email <> NULL) { 
        $this->db->like('Email', $email, 'both'); }
    if ($telephone <> NULL) { 
        $this->db->like('Telephone', $telephone, 'both'); 
    }
    
    $query = "CREATE TABLE SearchedClubs AS (" . $this->db->get_compiled_select() . ")";
    $this->db->query($query);
    

    【讨论】:

      猜你喜欢
      • 2014-08-27
      • 2021-01-30
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      相关资源
      最近更新 更多