Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 66447

Re: I'm trying to pull a record set and I'd like to load the data into an array

$
0
0

I've been thinking about this a bit more. If you want an array of all the results, it's extremely simple.

 

Build a comma-separated list of the record IDs using implode(), and then build a SQL query like this (I've used actual numbers to illustrate what the query should look like):

 

$sql = 'SELECT * FROM service WHERE fac_id IN (1,3,7,12,21,25,26)';

$result = $mysqli->query($sql);

$all = $result->fetch_all(MYSQLI_ASSOC);

 

This will create a multidimensional array with all the results in this format: $all[0]['fac_id'].

 

One caveat, though. Storing everything in an array consumes a lot of memory, which could slow the server down, or even run out of memory on a busy shared server. Ideally, you should process database results as received.


Viewing all articles
Browse latest Browse all 66447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>