We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do you implode a queries results?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
15 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Hopefully a quick one this.

I am creating a plugin that has a query in it which will bring back multiple results.

Once I have those results I want to create a comma separated string from them. I thought that I would just be able to do something like this but it’s not working :

$query = $DB->query("SELECT member_id FROM exp_members");
$comma_separated_ids = implode(",", $query);

N.B. This isn’t the actual query I’m running but just an example.

Can this sort of thing not be done like this? Do I have to use a for each loop or something? I’d really rather not have to if I don’t though. I just wanted to be able to take the database queries results array (I take it the results are in an array aren’t they?) and straight convert it into that kind of string.

Any help would be greatly appreciated.

Many thanks.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
15 years ago
Mark Bowen's avatar Mark Bowen

Oops sorry also meant to mention that the reason I need this as a string is that I want to then use it in another query as part of an IN clause such as :

SELECT *
FROM exp_member_data
WHERE member_id IN ($comma_separated_ids)

That kind of thing.

Any help would be appreciated on this.

Best wishes,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.