Skip to content Skip to sidebar Skip to footer

Spliting Mysql Data In 3 Columns Error

Morning, We have a script for spliting the data we get from a mysql database (based on this answer: https://stackoverflow.com/a/8660624/1067100) in a table with three columns, in t

Solution 1:

The queickest fix is that you need a "break" in the inner loop.

for ($i=0; $i < count($data)/3; $i++){
    for ($j=0; $j<3; $j++){
         if (($i * 3) + $j >= count($data)) {
             break;
         }

Note that you should save a fractional bit of computing power by storing count($data) in a variable - unless you expect the count to change.

$countOfData = count($data);
for ($i=0; $i < $countOfData/3; $i++){
    for ($j=0; $j<3; $j++){
         if (($i * 3) + $j >= $countOfData) {
             break;
         }

Post a Comment for "Spliting Mysql Data In 3 Columns Error"