Format the result of loop php -


i'm stuck of making table 4 columns, , data of table comes array, code i've done:

$sample // array , has 15 values inside <table> foreach($sample $x){ $rows="<td>$x</td>".$rows; $l++; if($l==4){ echo"<tr>".$rows."</tr>"; $l=0; $rows=""; } } </table> 

if i'm correct code produce table width 3 rows , 4 columns, missing content need include of data inside $sample need kind of output code.

[1][1][1][1] [1][1][1][1] [1][1][1][1] [1][1][1][0] 

the 1 array value of $sample while 0 has no value, because value og $ sample 15 only

try this:

<?php     echo "<table border='1'>";     $sample = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");          #with 15 rows     echo "<tr>";     $key   = 1;      foreach($sample $each){         if( ($key%4) == 0){             echo "<td>{$each}</td></tr><tr>";         }else{             echo "<td>{$each}</td>";         }         $key++;     }     echo "</table>"; ?> 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -