如何从codeigniter-query创建表?

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


背景是,我制作了一个额外的表格来搜索每个俱乐部的详细信息,您可以在其中搜索俱乐部名称的单个详细信息,或者您可以组合字段,例如俱乐部名称的一部分,让我们说街道名称的一部分,但是表中的某些字段可以为 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();


呼啦一阵风
浏览 156回答 1
1回答

慕码人8056858

简单的方法是$this->db->select('*');$this->db->from('Clubs');if ($clubname <> NULL) {&nbsp; &nbsp; $this->db->like('Clubname', $clubname, 'both'); }if ($street <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('Street', $street, 'both'); }if ($postalcode <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('Postalcode', $postalcode, 'both'); }if ($city <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('City', $city, 'both'); }if ($homepage <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('Homepage', $homepage, 'both'); }if ($email <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('Email', $email, 'both'); }if ($telephone <> NULL) {&nbsp;&nbsp; &nbsp; $this->db->like('Telephone', $telephone, 'both');&nbsp;}$query = "CREATE TABLE SearchedClubs AS (" . $this->db->get_compiled_select() . ")";$this->db->query($query);
打开App,查看更多内容
随时随地看视频慕课网APP