Re: [PHP] What kind of looping ?
try using $count=0; before the loop (while loop is fine) then before the end of the loop $count++; inside the loop if ($count % 4) { that is where you want it to break and start running the other code } so you would have $table = ""; $counter = 0; while ($tableset = mysql_fetch_array($result) ) { $table = ""; if ($counter % 4 == 0) { $table .= " FILE 0 FILE 1 FILE 2 FILE 3 "; } else { $table .= " FILE 4 FILE 5 FILE 6 FILE 7 "; } $counter++; } $table .= ""; something like that, if this doesnt get the total desired result try playing with the % 4 == 0 to like == 1 or 2, see if that gets a desired result. please please this is some psudo code I threw together you might need to tweek. --- Steve Maroney <[EMAIL PROTECTED]> wrote: > > Hey guys, > > I cant figure out what functions and/or looping I need to use for what I > need to do. Im reading a directory and pushing all the file names in the > directory into an arrary. > > I want to be able print out each element(file name) in the array into an > HTML table while limiting a certain number of elements for each row. > > 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. > > >FILE 0 FILE 1 FILE 2 FILE 3 >FILE 4 FILE 5 FILE 6 FILE 7 > > > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > = Dan McCullough --- "Theres no such thing as a problem unless the servers are on fire!" h: 603.444.9808 w: McCullough Family w: At Work __ Do You Yahoo!? Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] What kind of looping ?
"Steve Maroney" <[EMAIL PROTECTED]> wrote: > 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. > > >FILE 0 FILE 1 FILE 2 FILE 3 >FILE 4 FILE 5 FILE 6 FILE 7 > > > I would image I would use a for loop, but I cant figure it out. > Can somone assist me ? The % (modulus) operator is the key to this type of looping. I didn't test the code below, but I've done this enough times that I'm pretty sure it's correct. If not it should be pretty easy to correct after you test it. $columns = 4; $array_count = count( $file_list ); for ( $i = 0; $i < $array_count; $i++ ) { if ( $i % $columns == 0 ) { $o .= ''; } $o .= "{$file_list[$i]}"; if ( $i % $columns == $columns - 1 ) { $o .= ''; } } // Create blank table cells if final row doesn't use all columns. // You can get away without this on broken browsers like IE, but // then you'll generate invalid HTML and browsers like NS // won't display your pages. if ( $array_count % $columns > 0 ) { $o .= str_repeat( " ", $columns - ( $array_count % $columns ) ) . ""; } -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] What kind of looping ?
echo ""; while(list(,$fname) = each($file_list)) { if(!($cnt % 4) && $cnt++!=0) { echo ""; } echo "$fname"; } echo ""; 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. > > >FILE 0 FILE 1 FILE 2 FILE 3 >FILE 4 FILE 5 FILE 6 FILE 7 > > > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- Hank Marquardt <[EMAIL PROTECTED]> 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]