Welcome Guest, Not a member yet? Register   Sign In
Flexigrid expert query without active record
#1

[eluser]@HR13[/eluser]
i'm flexigrid CI mania, it's very useful and easy to use. But recently i have a trouble using query like this select ...,(select ... from ...) as sel1 from ... where ... and ... .
I'm tried use without active record, but error. I don't know what to do next
Anyone having trouble like me
#2

[eluser]jcavard[/eluser]
Your query is probably wrong.
#3

[eluser]@HR13[/eluser]
Hmmm, maybe right. But can someone tell me how to use a flexigrid without active record with $this->db->query() tag in ci, with example code.
Sql query : select id, (select name from tb_user where access = 1) as name from tb_login where login_as = "admin" and status = 2
#4

[eluser]jcavard[/eluser]
I'm not sure I understand... what's the problem?
Flexigrid is in no way dependant of active record. Just feed it whatever data from whatever source retreived in whatever way.

pull the data like this if you will
Code:
$handle = $this->db->query('select id, (select name from tb_user where access = 1) as name from tb_login where login_as = “admin” and status = 2');
then format the result into a nice JSON format, and feed flexigrid.

Also, you should post more details if you want us to help..
#5

[eluser]jcavard[/eluser]
also, your query, as you posted, probably is wrong. I just copy/paste it, but I realise now, the select part doesnt make sense, you proabably want to look at JOIN.
#6

[eluser]@HR13[/eluser]
Yes, I see something wrong with my query. That mean like this :
select tblog.id, (select count(id) from tb_post as tbpos where tblog.id = tbpos.id) as name from tb_login as tblog where tblog.login_as = “admin” and tblog.status = 2

The problem is I want to put in the model:
Some think in my mind:

Function flex_ajax(){
$query['main_query'] = 'select tblog.id, (select count(id) from tb_post as tbpos where tblog.id = tbpos.id) as name from tb_login as tblog where tblog.login_as = “admin” and tblog.status = 2
{SEARCH_STR}';
$query['count_query'] = 'select count(id) as record_count from tb_login as tblog where tblog.login_as = “admin” and tblog.status = 2
{SEARCH_STR}';
$build_query = $this->CI->flexigrid->build_query($query,false);
$return['result'] = $this->db->query($build_query['main_query']);
$rec_count = $this->db->query($build_query['count_query']);
$return['count'] = $rec_count->row()->record_count;
Return $return;
}

But the result its not comming, lazy loading unstopable.
The first I check option coloum and controler result it's not wrong, I test model with active record and a simple query.
It's show a result.
Thanks before ^^
#7

[eluser]mjsilva[/eluser]
For complex queries with flexigrid use a view, it's less headache




Theme © iAndrew 2016 - Forum software by © MyBB