Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4661
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!feeder.eweka.nl!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <2270584.FRqVoOGUtd@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <php@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sat, 28 Jan 2012 21:28:18 +0100 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 7Bit |
| Subject | Re: Fast/Easy way to extract a column from multi-dimensional array? |
| Newsgroups | comp.lang.php |
| References | <jfv06v01hoa@news6.newsguy.com> <gho6i7hj054un6dh301rn8hfaun1cb4e02@4ax.com> |
| Followup-To | comp.lang.php |
| MIME-Version | 1.0 |
| Lines | 55 |
| NNTP-Posting-Date | 28 Jan 2012 21:28:21 CET |
| NNTP-Posting-Host | 22d34d78.newsspool4.arcor-online.net |
| X-Trace | DXC=:[HX?YeJmTE0YVY]kmLTlD4IUK<Cl32<A4Fo<]lROoRA8kF<OcfhCOKj]Fh:bfXX[MDZm8W4\YJNL;?f@h5gMfbL;hQ?\>7BWcIgM64FKOcW`J |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.php:4661 |
Followups directed to: comp.lang.php
Show key headers only | View raw
Jeff North wrote:
> John Drako 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().
GROUP_CONCAT() could only return a string of the concatenated non-NULL
RecordIDs. That is probably not what the OP is looking for ("reuse in
other queries").
<http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html>
I fail to see how you could suggest such error-prone and expensive an
approach (first concatenation in MySQL, then splitting in PHP) when *the*
solution has been presented already.
Please skip the attribution novel next time.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Fast/Easy way to extract a column from multi-dimensional array? John Drako <jbravo556@gmail.removethis.com> - 2012-01-27 15:08 -0500
Re: Fast/Easy way to extract a column from multi-dimensional array? "J.O. Aho" <user@example.net> - 2012-01-27 21:50 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-27 22:49 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-01-27 21:52 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-27 22:42 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-27 22:55 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-01-27 23:49 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Jeff North <jnorthau@yahoo.com.au> - 2012-01-28 13:52 +1100
Re: Fast/Easy way to extract a column from multi-dimensional array? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 21:28 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? Arno Welzel <usenet@arnowelzel.de> - 2012-01-28 09:49 +0100
Re: Fast/Easy way to extract a column from multi-dimensional array? John Drako <jbravo556@gmail.removethis.com> - 2012-01-29 13:54 -0500
csiph-web