⚠ 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

Is there a query function?



Mohammed Zayan

Mohammed Zayan
  • profile picture
  • Member

Posted 31 July 2012 - 23:29 PM

Hi All,
I want a function like that in codeIgniter

$this->db->query(here is my query);

because I want to do queries like this


$query = "SELECT V.`name`, V.`mail`, V.`printDate`, V.`country`
FROM volunteers AS V
INNER JOIN volunteer_skills AS VS ON V.profileId = VS.profileId
INNER JOIN ist_skill AS S ON VS.skillId = S.skillId
WHERE S.skillId = {$skill_id} LIMIT {$limit1},{$limit2}";

OR How can I do this by the library??

web-johnny

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

Posted 31 July 2012 - 23:40 PM

[member='Mohammed Zayan'] this is not yet available in grocery CRUD. I have it in mind to do it soon (not planned yet but soon) as it is really helpful for many people. As a work around for now , is to use the set_model and add only one method the get_list method. For example:


function get_list()
{
$skill_id = $this->session->userdata('skill_id');

$progress=$this->db->query("SELECT V.`name`, V.`mail`, V.`printDate`, V.`country`
FROM volunteers AS V
INNER JOIN volunteer_skills AS VS ON V.profileId = VS.profileId
INNER JOIN ist_skill AS S ON VS.skillId = S.skillId
WHERE S.skillId = {$skill_id}");

$results_array=$progress->result();

return $results_array;
}


I know this is not the best solution but for now it is the only solution without changing the Core of grocery CRUD.

Hope it helps

ckm

ckm
  • profile picture
  • Member

Posted 06 August 2012 - 01:56 AM

I tried this but I'm getting the following error:

[color=#000000]Message: Undefined property: stdClass::$key
Filename: libraries/grocery_crud.php
Line Number: 1388[/color]

It seems like GC is not picking up the custom query.

Any ideas?

Thx.

Chris.

archanamapari

archanamapari
  • profile picture
  • Member

Posted 21 August 2012 - 15:30 PM

By set_model we can overwrite get_list method, but if we join multiple tables in get_list method, how can we display selected fields from various tables ?

Grid shows only the fields which are present in the main table (set by set_table method,which is called in controller).
Please suggest, how can we display selected fields from various table.

allphoneso

allphoneso
  • profile picture
  • Member

Posted 08 July 2013 - 11:19 AM

Hi Jhonny,

 

 

can you give step by step how to implement you advice?

 

 

thanks.


davidoster

davidoster
  • profile picture
  • Member

Posted 09 July 2013 - 08:57 AM

Hi Jhonny,

 

 

can you give step by step how to implement you advice?

 

 

thanks.

 

Follow the instructions here: http://www.grocerycrud.com/documentation/options_functions/set_model

and then alter the get_list function by copying the original to the newly created model you did on the previous step.