[eluser]Isern Palaus[/eluser]
[quote author="dallen33" date="1300234871"]I'm generating some JSON for an autocomplete form. I found this code online which works beautifully, but whenever I try to re-factor it to CodeIgniter's active record style, it never works. Any ideas how I could do this?
Code:
$return_arr = array();
$query = mysql_query("SELECT * FROM clients");
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)):
$row_array['value'] = $row['name'];
array_push($return_arr, $row_array);
endwhile;
For example, this doesn't work:
Code:
$query = $this->db->get('clients');
[/quote]
You've to generate the results, so first:
Code:
$query = $this->db->get("clients")->result_array();
I usually do ->result() and get and object but as you need an array, it's more apropiate. Then:
Code:
$result = array(); // I first create and array so I'll never get a not defined if there is no result.
foreach($query as $row) // I dont use {} because u only need one line
$result[] = $row;
This should work ;-)