We have 43 guests online
   
PHP Scripts arrow Free PHP Tutorials arrow Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP 
Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP

Table rows
User Rating: / 9
PoorBest 

A common function on many php (or other data driven) sites is to loop through an array and write the contents of the array to the page. It is preferable to spread your data over multiple columns instead of writing it all in a straight list thus forcing your readers to scroll forever. Here is an easy way to dynamically write your cells and rows using expressions.

  1. <html><body><table><tr>
  2. <?
  3. $names=explode(",","Joe,Lisa,Bill,Roger,Fred,Kenney");
  4. $counter=-1;
  5. while (list(,$value)=each ($names))
  6.  {  $counter=$counter+1;
  7. echo "<td>" . $names[$counter] . "&nbsp </td>"
  8. //this is the key - if field  has no remainder then field is in second column
  9. $newrow=($counter % 3);
  10. //echo $newrow;
  11. if ($newrow == 2) echo "</tr><tr>" ;                   
  12. } // end of while
  13. //****This will write the data in three cells per row. To only do two cells
  14. //** per row change the 3 in the $newrow definition to a 2 and the
  15. //** comparison to a 1.
  16. ?>
  17. <td>&nbsp</td></tr></table></body></html>

 

 

Directory Stats

There are 882 listing and 46 categories in our website

Change Language