⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Having trouble building a where query



richb201
  • profile picture
  • Member

Posted 24 December 2017 - 16:02 PM

I am trying to build a where statement. The reason I am building it by hand is that although I can get it to work with one filter I can't get it to work with more than two. I saw a recommendation StackOverflow to build it by hand and that is what i am trying to do. I also tried fooling with OR_where but I am not sure that is supported in GC. I did see a 

 

attempt1:

 

This is my current try. Here is what I see in my debugger after running this line. 

 

$where="'email'=".$email_encrypt." OR 'email'=".$email_unencrypt." OR 'email'=N/A";

$crud->where($where);

 

$where='email'=richb201@gmail.com OR 'email'=cmljaGIyMDFAZ21haWwuY29t OR 'email'=N/A

 

attempt2:I have also tried it by using

 

$crud->where('email',base64_decode( urldecode( $this->session->userdata('userid') )));
$crud->OR_where('email',$this->session->userdata('userid'));
$crud->OR_where ('email','N/A');

$crud->set_relation_n_n('activities', 'relation', 'standard_activities', 'activity_id', 'standard_id', 'activity','priority');

 

 

This seems to fill in the where and the OR_where elements of $crud ok but doesn't seem to actually work when I run my app. By that I mean that although the first where seems to work, the additioanal OR_where's don't.  I did see a post up here from a few years ago where the solution was to build the query by hand. but as you can see from my first attempt, but I can't seem to get the string correct. 


Amit Shah
  • profile picture
  • Member

Posted 24 December 2017 - 18:24 PM

well you can simply use where_in instead of such complex ORs ...

Try - it might give u solution


richb201
  • profile picture
  • Member

Posted 24 December 2017 - 21:03 PM

[attachment=1270:Capture.JPG]Thanks Amit. Is or_where_in defined in GC?

 

BTW, and this may be important, the place where this is not working is the "add record". See the snip attached. I was hoping to only show choices that are specifically for the current user or "N/A". But it seems to show all 5 choices. 

 

So I built the "where clause" to use as the last parameter of the set_relation_n_n. Now it seems to have an effect, just not the right effect. I think the where clause is AND ing the elements in the array. I want to OR them. Any ideas?


Amit Shah
  • profile picture
  • Member

Posted 25 December 2017 - 09:02 AM

well... you want to use a where clause in for filtering rows in GC OR Set relation .. either way around, there you can do all the same things what you can do it in CI ... you can use the Active Records features or you can use custom where clause - you can just built the where clause in a simple string - put it in an array and pass the same in where function - that too works absolutely fine.


richb201
  • profile picture
  • Member

Posted 26 December 2017 - 01:00 AM

But what will this filter? The Selection table or the This table?

 

https://www.grocerycrud.com/documentation/options_functions/set_relation_n_n

 

I am trying to filter the Selection table. 


Amit Shah
  • profile picture
  • Member

Posted 26 December 2017 - 04:38 AM

Well - i believe the solution was already set for you ... the function expects a string - u just pass the string -

"email in ('$email_encrypt','$email_unencrypt','N/A')"

That should help you get your desired output..

 

Happy GCing :)


richb201
  • profile picture
  • Member

Posted 27 December 2017 - 03:39 AM

works perfectly. Thanks!