There seems to be a problem with the logic in your code:
First: Database tables will have a number of rows that normally increase over time. You don't want to hardcode in your PHP code that you want to extract 8 rows.
Second: Your second FOR statement will allways extract records number 1 and 2 from the database. Since it is nested within another for loop, this will happen 4 times, but always the same records will be extracted.
Third: You are running multiple SELECT statements to the database: not ideal.
The best thing would be to have a SELECT statement that brought over all the records that you need. And then use a WHILE loop to go over the records and represent them as you want.
Hope this helps