Welcome Guest, Not a member yet? Register   Sign In
Extracting all the id's from a query and saving them as a comma seperated list
#1

[eluser]jtotheb[/eluser]
I'm trying to run a query using AR and then save back to another table all the ID's from that query as a comma seperated list.

I'm trying to use array_pop($array) and then join (', ', $array) . ", and $last";

But i think the problem i'm having is getting the result correctly out of the query result.

If anyone could give me a wee hand with this, that would be fantastic!
#2

[eluser]TheFuzzy0ne[/eluser]
Stupid question, I know, but what's AR?
#3

[eluser]jtotheb[/eluser]
AR = Active record

Not stupid at all, i should have been clear with my original post.
#4

[eluser]TheFuzzy0ne[/eluser]
Of course. I should have known that. I've read about it a lot in the past, but not actually used it.

Can you post some code so we can see the query you're making, the results you're getting back, and how you're processing it?
#5

[eluser]jtotheb[/eluser]
The query is simply something like this.

$this->db->select('id');

$this->db->from('table_name');

$this->db->get();

And i want to get all the id's into a comma seperated list.

Cheers
#6

[eluser]xwero[/eluser]
Code:
$array = array();
foreach($query->result() as $row)
{
   $array[] = $row->id;
}
$commastr = implode(',',$array);
php5 code for php4 you have to use $query->result_array() and $row['id']
#7

[eluser]jtotheb[/eluser]
Php5 is where i'm at so that is great.

I really struggle with the myriad ways of getting data out from AR queries, i find myself getting quite quite lost a lot of the time. I think i need to write myself some form of cheat sheet.

Thanks a lot xwero, i really appreciate your help.




Theme © iAndrew 2016 - Forum software by © MyBB