亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從codeigniter-query創建表?

如何從codeigniter-query創建表?

PHP
呼啦一陣風 2021-11-26 17:54:18
我想從以下查詢創建一個表...背景是,我制作了一個額外的表格來搜索每個俱樂部的詳細信息,您可以在其中搜索俱樂部名稱的單個詳細信息,或者您可以組合字段,例如俱樂部名稱的一部分,讓我們說街道名稱的一部分,但是表中的某些字段可以為 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();
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

簡單的方法是


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


查看完整回答
反對 回復 2021-11-26
  • 1 回答
  • 0 關注
  • 185 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號