Senin, 13 Juli 2009

Table rows

Bookmark and Share

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. $names=explode(",","Joe,Lisa,Bill,Roger,Fred,Kenney");






  2. $counter=-1;






  3. while (list(,$value)=each ($names))






  4. { $counter=$counter+1;






  5. ";





  6. //this is the key - if field has no remainder then field is in second column






  7. $newrow=($counter % 3);






  8. //echo $newrow;






  9. if ($newrow == 2) echo "
  10. " ;





  11. } // end of while






  12. //****This will write the data in three cells per row. To only do two cells






  13. //** per row change the 3 in the $newrow definition to a 2 and the






  14. //** comparison to a 1.






  15. ?>






  16. " . $names[$counter] . "&nbsp
    &nbsp


Artikel yang berhubungan



1 komentar:

Locomotives mengatakan...

nice post
:)

Posting Komentar

Followers


junkelse by Junkelse. Powered by Blogger and Supported by kuchino.blogspot.com