Knowledgebase

PHP nested loop question

Posted by croakingtoad, 03-12-2007, 02:32 PM
Hey everyone, I am trying to create a bit of code to loop through a mysql query response and output some html, etc. What I am wanting is to loop through the results, 4 at a time. Basically, do this-- output-
loop through first 4 data results and output the following 4 times -
$data[$i]
then output-
to close the first div then do the whole loopset over again for the next 4 records. I'm trying my best but can't wrap my mind around what I'm doing wrong. I know it's in the counting but thought maybe someone here can fix me up. Here's what my limited experience has come up with--

Posted by mikey1090, 03-13-2007, 05:19 AM
perhaps you could show us what the $query is

Posted by ptrok, 03-13-2007, 08:22 AM
Hi Croakingtoad, maybe you could slightly change your approach. I had to split my results from a query in a similar fashion sometime back and heres what I did. 1. Place your query result into an array (You end up with an array of an array here) 2. Use the chunk function to split that array into an array of a new array that contains the 4 sets of fields that you want to manipulate. (yes thats right its now a 3 dimensional array) 3. Use 3 nested loops to access results in sets of the chunk you split the first array into Hope this is useful to you Cheers Paul

Posted by arkin, 03-13-2007, 12:49 PM
Your php is far too in depth. It can be made simple. Should do the trick.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Tomsyer server offline (Views: 636)
Software raid (Views: 523)


Language:

Client Login

Email

Password

Remember Me

Search