Welcome Guest, Not a member yet? Register   Sign In
list_fields not working on query
#1

[eluser]cogito[/eluser]
Hi,
I need to use list_fields on my query result (usgin mysql), but it's not returning anything.
It's working fine for when called directly from db using table name.

How can I make it work for query as well?
Am I missing something or is it a bug?

thanks,
Slawek
#2

[eluser]InsiteFX[/eluser]
Post your code or we will not be able to help you!

InsiteFX
#3

[eluser]cogito[/eluser]
I do not have any particular code, I have just tried to create a general code to get query result and display it as a html table. I have tried to get query from model and call
Code:
$query->list_fields()
to get fields (get user friendly column names etc.).
But the function doesn't return anything. It works when I call
Code:
$this->db->list_fields('users');
I'm doing it currently, but it gives two queries to database.
Should I do anything more to enable list_fields() for a query returned by
Code:
$query = $this->db->get('users');
?
I have used most simple calls, examples from user guide (user guide).
I'm using simple MySQL database, currently connecting to it as a root (I will change it later on to use more restricted account).
#4

[eluser]InsiteFX[/eluser]
You can read up on how to do it here:

CodeIgniter User Guide - The Database Class

CodeIgniter also has a Table Class, you can find it here:

CodeIgniter User Guide - HTML Table Class

InsiteFX
#5

[eluser]cogito[/eluser]
I do read that section of user guide. My question is why example code from user guide to get list_fields() is not working for query object ($query->list_fields()) while it's working when called for a specified table ($this->db->list_fields('users')?
#6

[eluser]InsiteFX[/eluser]
That is because it is listing all the column names in the table!

Maybe you need to explain better of what you are trying to do.

InsiteFX
#7

[eluser]Unknown[/eluser]
I'm having a similar problem. The second call to the result->list_fields method returns an empty array. The full table version works fine. Here is the code and the output:

Code:
Code:
$query = $this->db->get($mytablename);
echo 'this is the first call on table results: <br />';
print_r($query->list_fields());
echo '<br />this is the second call on table results: <br />';
print_r($query->list_fields());
$query = $this->db->get('tad_keywords');
echo '<br />this is the first call on full table: <br />';
print_r($this->db->list_fields($mytablename));
echo '<br />this is the second call on full table: <br />';
print_r($query->list_fields($mytablename));
Output:
this is the first call on table results:
Array ( [0] => id [1] => keyword [2] => aliaslist [3] => campaign_id [4] => contentcat [5] => keypadalias [6] => datafeed_id )
this is the second call on table results:
Array ( )
this is the first call on full table:
Array ( [0] => id [1] => keyword [2] => aliaslist [3] => campaign_id [4] => contentcat [5] => keypadalias [6] => datafeed_id )
this is the second call on full table:
Array ( [0] => id [1] => keyword [2] => aliaslist [3] => campaign_id [4] => contentcat [5] => keypadalias [6] => datafeed_id )

For now, I'm just stuffing the results of the first call in a variable and using that for repeats.
#8

[eluser]toopay[/eluser]
Code:
$query = $this->db->get($mytablename);
$list1 = $query->list_fields();
echo 'this is the first call on table results: <br />';
print_r($list1);
echo '<br />this is the second call on table results: <br />';
print_r($list1);
$query = $this->db->get('tad_keywords');
$list2 = $query->list_fields($mytablename);
echo '<br />this is the first call on full table: <br />';
print_r($this->db->list_fields($list2));
echo '<br />this is the second call on full table: <br />';
print_r($query->list_fields($list2));




Theme © iAndrew 2016 - Forum software by © MyBB