FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Fast/Easy way to extract a column from multi-dimensional array?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Fast/Easy way to extract a column from multi-dimensional array? [message #176838 is a reply to message #176831] Sat, 28 January 2012 02:52 Go to previous messageGo to previous message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma:
Member
On Fri, 27 Jan 2012 15:08:01 -0500, in comp.lang.php John Drako
<jbravo556(at)gmail(dot)removethis(dot)com>
<jfv06v01hoa(at)news6(dot)newsguy(dot)com> wrote:

> | I'm looking for a way to get all the values from the column of a two
> | dimensional array.
> |
> | For example, I have a query on a mysql database that returns 10 rows
> | from the database, I would like to quickly (read low cpu load) extract
> | all the IDs from all the rows returned to reuse in another query.
> |
> | So let's say I use:
> |
> | $arr = mysqli_fetch_all($result, MYSQLI_ASSOC);
> |
> | and $arr looks like:
> |
> | RecordID, name, last name, title
> | RecordID, name, last name, title
> | RecordID, name, last name, title
> | RecordID, name, last name, title
> | RecordID, name, last name, title
> | RecordID, name, last name, title
> | etc...
> |
> | I need to get all the 'RecordID' from the results to reuse in other
> | queries.
> |
> | Is there a built in PHP function (compiled code) to accomplish this?
> | I've read the definitions of all the functions related to arrays and if
> | it exists, I didn't find it.
> |
> | The site is very busy and CPU cycles count. I'm trying to avoid left
> | joining three gigantic tables.

Let the database do it for you - look at group_concat().
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: approaches to PHP-based application interface?
Next Topic: php+html mixup in displaying multidimensional array in html tables
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 00:46:28 GMT 2024

Total time taken to generate the page: 0.05581 seconds