Re: What kind of looping ?

From: Date: Tue, 27 Nov 2001 20:05:42 +0000
Subject: Re: What kind of looping ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75812@lists.php.net to get a copy of this message
echo "<table><tr>"; while(list(,$fname) = each($file_list)) { if(!($cnt % 4) && $cnt++!=0) { echo "</tr><tr>"; } echo "<td>$fname</td>"; } echo "</tr></table>"; Didn't actually test that, but it should be close ... the important piece is ($cnt % 4) ... modulo arithmetic is your friend. That and thinking in terms of cells, not rows. > Example: > $image_dir = opendir("../images/bullets/"); > while ($file = readdir($image_dir)) { $file_list[] = $file; }; > > Now $file_list[] has some number a file names. I want print 4 file names > into a row. Each file name has to be in its on cell. > > <table> > <tr> <td>FILE 0</td> <td>FILE 1</td> <td>FILE > 2</td> <td>FILE 3</td> </tr> > <tr> <td>FILE 4</td> <td>FILE 5</td> <td>FILE > 6</td> <td>FILE 7</td> </tr> > </table> > > I would image I would use a for loop, but I cant figure it out. > Can somone assist me ? > > Thanks, > Steve > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -- Hank Marquardt <hank@yerpso.net> http://web.yerpso.net GPG Id: 2BB5E60C Fingerprint: D807 61BC FD18 370A AC1D 3EDF 2BF9 8A2D 2BB5 E60C *** Web Development: PHP, MySQL/PgSQL - Network Admin: Debian/FreeBSD *** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild *** Beginning PHP -- Starts January 7, 2002 *** See http://www.hwg.org/services/classes

« previous php.general (#75812) next »