为了账号安全,请及时绑定邮箱和手机立即绑定

如何从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 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信