⚠ 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

Custom query



vnt
  • profile picture
  • Member

Posted 08 February 2012 - 13:32 PM

Hi,
how do I add a custom query?

[color=#339933]where stato = 1;[/color]
[color=#000088]$crud[/color][color=#339933]->[/color][color=#004000]set_relation[/color][color=#009900]([/color][color=#0000ff]'idUser'[/color][color=#339933],[/color][color=#0000ff]'name'[/color][color=#339933],[/color][color=#0000ff]'surname'[/color][color=#009900])[/color][color=#339933];[/color]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 February 2012 - 18:56 PM

For now you can only do it with the set_model method. From the NEW version (1.2) [not yet released] you will be able to add your where clause to your 4th segment. For example:

$crud->set_relation('idUser','users','surname',array('stato' => 1));


I think that you doing it wrong anyway if you want to take multiple fields from your related table you can do this:


$crud->set_relation('idUser','users','{surname} {name}');

the "{" and"}" symbol is the field from the related table you can write whatever you like for example:


$crud->set_relation('idUser','users','{surname} {name} ({email})');

Just make sure that the fields exists to the other table.

vnt
  • profile picture
  • Member

Posted 09 February 2012 - 20:51 PM

Thank a lot Johnny!

In the new version, you can also add a condition for the table?

[color=#339933]where id = $_SESSION['id'];[/color]

$crud->set_table('tb_users');
$crud->columns('email','fname','lname','dob','gender','country','state','city','address');

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 February 2012 - 22:18 PM

This is already done . You can have the

$crud->where('id',$_SESSION['id']);

It works exactly the same way as codeigniter's where.

vnt
  • profile picture
  • Member

Posted 12 February 2012 - 21:03 PM

Thank you,
when released the new version?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 12 February 2012 - 22:57 PM

It will be a little later that the normal releases as it will have major changes in core. I suppose at 15-30 of March.

goFrendiAsgard
  • profile picture
  • Member

Posted 22 August 2012 - 04:55 AM

Hi, just to make sure, should it work with set_relation_n_n?

I mean, can we do this:

$crud->set_relation_n_n('items',
'tb_bill_detail', 'tb_items',
'bill_id', 'item_id', '{id} - {name}');

In my case it doesn't work. I wonder if it is unsupported (yet) feature or a bug

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 August 2012 - 06:25 AM

No [member='goFrendiAsgard'] it is still not supported from grocery CRUD yet.

goFrendiAsgard
  • profile picture
  • Member

Posted 22 August 2012 - 07:17 AM

Hi, I'm currently work on it. There are 3 functions in groceryCRUD model I need to change.[list]
[*]relation_n_n_queries
[*]get_relation_n_n_selection_array
[*]get_relation_n_n_unselected_array
[/list]
I've successfully make it for add & edit form (related to the 2 last functions).
But still get some horrible error when trying to deal with the first function.

I'll inform you later.

[b]EDIT:[/b] already done, I'll make a pull request soon :)

goFrendiAsgard
  • profile picture
  • Member

Posted 22 August 2012 - 07:37 AM

Hi, @web-johnny I've already make a pull request:
https://github.com/scoumbourdis/grocery-crud/pull/87

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 August 2012 - 23:03 PM

Thanks a lot [member='goFrendiAsgard']

I just accepted and everything seems to work fine.

goFrendiAsgard
  • profile picture
  • Member

Posted 22 August 2012 - 23:42 PM

Great,... glad to help.

And I think I've just discover that strpos will return false if there is no character in the string http://php.net/manual/en/function.strpos.php I think I've do a lot of "mistakes" in my general code, by assuming it will return -1. Thanks for your fix :P