Welcome Guest, Not a member yet? Register   Sign In
adding a cell to an array using db->query
#1

[eluser]thiswayup[/eluser]
Hi

I have a query which returns a series of cells of data from a $this->db->query($sql) in the controller. What I want to do is foreach row of data, concatenate two of the cells and create a new cell then add it back to the array? For example, if i had an array:
A 1
B 2
C 3
Then we can after processing the array
A 1 A1
B 2 B2
C 3 C3

I was going to do it all in sql but I need a php function to do a urlencode. Initially I tried
Quote: for($i=0; $i < $listProducts->num_rows(); $i++){
$listProducts[$i]['prodUrl'] = '/index.php/product/'.
urlencode($listProducts[$i]['ProductName']).
'/'.$listProducts[$i]['PK_Product'];
}

But then realised that the return from $this->db->query($sql) isnt an associative array.

help?
#2

[eluser]jedd[/eluser]
[quote author="thiswayup" date="1256857761"]
But then realised that the return from $this->db->query($sql) isnt an associative array.
[/quote]

Do all your problems go away when you read the [url="/user_guide/database/results.html"]Generating Query Results[/url] page of the user guide, and discover the ->result_array() function?




Theme © iAndrew 2016 - Forum software by © MyBB