Split php mysql data into 20 rows per column <p>I want to split the data from php mysql into 20 rows per column. Below is my code:</p> <pre><code>while($row = mysql_fetch_assoc($result)) { $id[] = $row['id']; } for($i = 0; $i &lt; 20; $i++) { echo '&lt;table&gt;&lt;tr&gt;'; for ($j = 0; $j &lt; (count($id)-1)/20; $j++) { echo '&lt;td&gt;'.$id[$i + $j * 20].'&lt;/td&gt;'; } echo '&lt;/tr&gt;&lt;tr&gt;'; } echo '&lt;/tr&gt;&lt;/table&gt;'; </code></pre> <p>Let's say I have 21 rows, and the code only output 20 rows, and the 21th row is missing.</p> <p>And if there are 22 rows (as long as the remainder after divided by 20 is more than or less than by 1), there is <code>undefined offset 22, undefined offset 23.....</code> errors.</p> <p>There is something wrong with the inner <code>for</code> loop, but I cannot fix it. How can I fix this error?</p>