Jump to content


[BUG] in HAVING clause when using where and search

having where search all columns

  • Please log in to reply
5 replies to this topic

#1 Ruben Vanhoeyveld

Ruben Vanhoeyveld

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 19 September 2013 - 06:11 PM

I'm having a problem when using $crud->where() and use search on all columns.

 

This is my code:

			$crud = new grocery_CRUD();
			$crud->where('leads.deleted','0');

			$crud->set_table('leads');
			$crud->set_subject('Lead');
			$crud->set_primary_key('id');
			$crud->columns('firstname','lastname','email','street','country', 'locale_id');
			$crud->display_as('firstname','First name')
				 ->display_as('lastname','Last name')
				 ->display_as('email','Email address')
				 ->display_as('locale_id','Language')
				 ->display_as('agent_id','Agent')
				 ->display_as('sex_id','Gender')
				 ->display_as('lead_type_id','Lead type');
			$crud->set_relation('locale_id','locales','name');
			$crud->set_relation('lead_type_id','lead_types','name');
			$crud->set_relation('sex_id','sexes','name');
			$crud->set_crud_url_path('/leads');
			$crud->unset_add_fields('deleted');
			$crud->unset_edit_fields('agent_id', 'coworker_id', 'deleted');
			$crud->change_field_type('agent_id','invisible');
			$crud->change_field_type('coworker_id','invisible');
			$crud->required_fields('firstname', 'lastname', 'date_of_birth', 'email', 'phone');
			$crud->callback_before_update(array($this,'set_agent_coworker'));
			$crud->callback_before_insert(array($this,'set_agent_coworker'));
			$crud->callback_delete(array($this,'set_deleted_one'));
			$output = $crud->render();

			$this->load->view('leads', $output);

Request url:

/leads/ajax_list_info

 

Request parameters:

search_text: sch
search_field:
per_page: 25
order_by[0]: firstname
order_by[1]: asc
page: 1
 

 

This is the error being thrown:

 


 

A Database Error Occurred

Error Number: 1054

Unknown column 'leads.deleted' in 'having clause'

SELECT COUNT(*) AS `numrows`FROM (`leads`)LEFT JOIN `locales` as j6a51f7a4 ON `j6a51f7a4`.`id` = `leads`.`locale_id`LEFT JOIN `lead_types` as j9990a220 ON `j9990a220`.`id` = `leads`.`lead_type_id`LEFT JOIN `sexes` as je5ad4385 ON `je5ad4385`.`id` = `leads`.`sex_id`WHERE `leads`.`deleted` = '0'AND `firstname` LIKE '%sch%'OR `lastname` LIKE '%sch%'OR `email` LIKE '%sch%'OR `street` LIKE '%sch%'OR `country` LIKE '%sch%'OR `j6a51f7a4`.`name` LIKE '%sch%'HAVING `leads`.`deleted` = '0'

Filename: /models/grocery_crud_model.php

Line Number: 191

 

 

 

The way to solve this problem is to add the HAVING column(s) to the SELECT part. You CANNOT put columns in the HAVING clause without selecting them first!

 

Could this please be fixed?



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 20 September 2013 - 08:16 PM

Hello and welcome to the forums .

Could you please post this as an issue at : https://github.com/s...ery-crud/issues

Thank you.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#3 Ruben Vanhoeyveld

Ruben Vanhoeyveld

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 27 September 2013 - 10:12 PM

I can't get this fixed.. Can anyone look at this?



#4 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 29 September 2013 - 06:48 AM

Did you post an issue on github? If yes then you need to wait.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#5 wdj315

wdj315

    Newbie

  • Members
  • Pip
  • 1 posts
  • LocationTAIWAN

Posted 08 July 2018 - 10:22 AM

Did you post an issue on github? If yes then you need to wait.

He did,but it seems no one take care  :(  https://github.com/s...crud/issues/243

It had been 5 years ago....  :o

I have same issue and after some headcache time, I find a solution.

Even I don't think this is a good one, but it did solve my problem for now.

just mark these three line in Grocery_CRUD.php around line 643

				/*if(!empty($this->where))
					foreach($this->where as $where)
						$this->basic_model->having($where[0],$where[1],$where[2]);*/

still hope someone can figure out and fix that bug:)



#6 rumena

rumena

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 05 November 2019 - 10:06 AM

 

He did,but it seems no one take care  :(  https://github.com/s...crud/issues/243

It had been 5 years ago....  :o

I have same issue and after some headcache time, I find a solution.

Even I don't think this is a good one, but it did solve my problem for now.

just mark these three line in Grocery_CRUD.php around line 643

				/*if(!empty($this->where))
					foreach($this->where as $where)
						$this->basic_model->having($where[0],$where[1],$where[2]);*/

still hope someone can figure out and fix that bug:)

 

Thank you, wdj315 ! Your solution works for me. 







Also tagged with one or more of these keywords: having, where, search, all, columns

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users