Best approach to split mysqli result into smaller parts

I am sure there is out some good premade libraries for bootstrap to make an image gallery. So might wanna google for them too. So you don’t need to reinvent the wheel.

Good idea I’ll take a look.

I’ve actually already written the gallery and got it live but it’s flat html and I want to change that to be powered by a database to make it easier to maintain.

Cheers

Matt

Hi all
for anyone following…

I have got this workimg as I need it to:

  • get the data as a result object
  • pass that data that to an array using fetchassoc for each row
  • then use arraychunk on the new array to split that code into sets of 4 to generate the required html (the code I posted above)

Thanks everyone for their input

Cheers

Matt

1 Like

You can combine #1 and #2 using fetch_all() method, making it like

$res = $db->query("...");
$data = $res->fetch_all(MYSQLI_ASSOC);
$chunkArray = array_chunk($data, $numberOfColumns);
1 Like

Thanks - I did read a little about fetch all at one point. That seems sensible, I’ll look at it more, thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.