i want to create a table from the following query...
background is, i made an extra form to search for detailed informations about each club, where you can search for either for single details of the club name or you can combine fields like parts of the club name and lets say part of the street name but some of the fields in the table can be NULL. so i implemented these IF ELSE and LIKE statements. this works fine, but how to put these $query into a table, like in 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();
The easy way would be
$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);