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 #176864 is a reply to message #176839] Sun, 29 January 2012 18:54 Go to previous message
John Drako is currently offline  John Drako
Messages: 5
Registered: December 2011
Karma:
Junior Member
On Sat, 28 Jan 2012 03:49:08 -0500, Arno Welzel wrote
(in article <4F23B684(dot)8030602(at)arnowelzel(dot)de>):

> John Drako, 2012-01-27 21:08:
>
>> 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.
> [...]
>> The site is very busy and CPU cycles count. I'm trying to avoid left
>> joining three gigantic tables.
>
> You always query *all* records with every request?
>
> And do you already use some kind of byte code cache (XCache etc.)? This
> also helps a lot to reduce the CPU load and the scripts can be executed
> 3-4 times faster, since the interpretation will only be done once and
> further requests get served by the cached byte code.

Thank you all for the suggestions. I've learned a lot.

I've used your suggestions and I benchmarked the table joins against the
function fetching after. One db request with a single 3-Tables join vs
one db request following by getting all the id and then followed by two
db requests proved that this is best done by joining the tables.

The initial database request was returning results in 0.002secs (avg),
and after joining the three tables it was returning results in 0.0021
seconds (avg), so the price was quite insignificant.
[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: Tue Nov 12 21:33:48 GMT 2024

Total time taken to generate the page: 0.05199 seconds