如何从 codeigniter-query 创建 table?

how to create table from codeigniter-query?

我想根据以下查询创建一个 table...

背景是,我制作了一个额外的表格来搜索有关每个俱乐部的详细信息,您可以在其中搜索俱乐部名称的单个详细信息,或者您可以组合字段,例如俱乐部名称的一部分,让我们说一部分街道名称,但 table 中的某些字段可以为 NULL。所以我实现了这些 IF ELSE 和 LIKE 语句。这工作正常,但如何将这些 $query 放入 table,如 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();

简单的方法是

$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);