RE: RE: RE: [PHP] cell iterations in loop

From: Date: Thu, 26 Apr 2001 23:06:16 +0000
Subject: RE: RE: RE: [PHP] cell iterations in loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50525@lists.php.net to get a copy of this message
Ok, after a few hours of messing here and there I've got it to work. you can adjust for any number of columns, and the pictures and it makes solid tables. Thanks, for all of the help <snip> <table width="450" border="1" align="center"> <?php //set this number to the columns you would like $columns = 7; $pictures = 25;//could be from a database query echo "<tr>\n"; for ($x=1; $x<=$pictures; $x++) { echo "<td>".$x."</td>\n"; if ($x % $columns == 0) { $loopcount++; if ($loopcount < $x ) { echo "</tr>\n"; } else { echo "</tr>\n<tr>"; } } } $test = (($loopcount + 1) * $columns); $td = (($loopcount + 1) * $columns) - ($x -1); if($td != $columns) { for ($x=0; $x<$td; $x++) { echo "<td><b>EMPTY</b></td>\n"; } } #also added in if($x % $columns != 0) { #then we know that it did not end completely, so echo you're final </tr> echo "</tr>\n"; } ?> </table> </snip> Jerry Lake - jerryl@europa.com Interface Engineering Technician Europa Communications - http://www.europa.com Pacifier Online - http://www.pacifier.com -----Original Message----- From: dempsejn@georgetown.edu [mailto:dempsejn@georgetown.edu] Sent: Thursday, April 26, 2001 2:26 PM To: Jerry Lake Cc: php-general@lists.php.net Subject: Re: RE: RE: [PHP] cell iterations in loop ahhhhh, i got it... ok, try this: $length is arbitrary... $x is your counter... do the loop as before, but each time through the loop, $loopcount++; So, if you do the loop 5 times, $loopcount == 5. Then, at the end, $length - ($loopcount*$x) gives you the amount of <td> </td>'s to echo. Put another for loop with these parameters after you've printed your normal td's...you could do this all in one for loop, and would just need some more if statements... i think this is what you need...let me know how it goes... -jack ----- Original Message ----- From: "Jerry Lake" <jerryl@europa.com> Date: Thursday, April 26, 2001 5:20 pm Subject: RE: RE: [PHP] cell iterations in loop > Right, I understand that > if I use <td></td> it is blank space > if I use <td> </td> it is an empty cell > > right now $length is set at 42 (this is arbitrary) > and there needs to be two empty cells at the end of > the last row. if length is 41 I will need 3 and 40 > will need 4. but if I don't know what the value of > $length is going to be on a dynamic page such as > showing "x" amount of images from a folder. I need > for the loop to know how many "<td> </td>" to > echo out at the end depending on the $length; > > I apologize if I am not explaining this very well. > I usually am quite concise. > > Jerry Lake - jerryl@europa.com > Interface Engineering Technician > Europa Communications - http://www.europa.com > Pacifier Online - http://www.pacifier.com > > > -----Original Message----- > From: dempsejn@georgetown.edu [mailto:dempsejn@georgetown.edu] > Sent: Thursday, April 26, 2001 2:00 PM > To: Jerry Lake > Cc: php-general@lists.php.net > Subject: Re: RE: [PHP] cell iterations in loop > > > ok, again, trying to understand "blank space"...but, try this: > if you print out <td></td> you'll get something i think you're > referring to > as blank space... > try using a nonbreaking space in there...either or a space in the > code; this will force > the "emptiness" to show up... > > -jack > > ----- Original Message ----- > From: "Jerry Lake" <jerryl@europa.com> > Date: Thursday, April 26, 2001 4:54 pm > Subject: RE: [PHP] cell iterations in loop > > > Thanks, that worked with the removal > > of the first if clause for part 2 of > > my question, as far as part one, I will > > try to explain better. if you view the > > chunk of code in a browser you will get > > a table with borders number 1-43 however > > there will be a blank space at the end > > where 44 & 45 would be. how can I make > > the loop echo enough "<td> </td>" lines > > to show empty cells instead of blank space > > regardless of the number of cells I am > > creating ? > > > > Jerry Lake - jerryl@europa.com > > Interface Engineering Technician > > Europa Communications - http://www.europa.com > > Pacifier Online - http://www.pacifier.com > > > > > > -----Original Message----- > > From: Jack Dempsey [mailto:dempsejn@georgetown.edu] > > Sent: Thursday, April 26, 2001 1:18 PM > > To: php-general@lists.php.net; Jerry Lake > > Subject: RE: [PHP] cell iterations in loop > > > > > > I'm a little unclear as to what you're trying to do, but here's my > > interpretation: > > > > problem 2: if it ends on a complete row... > > solution: put the echoing of the first and last tr's inside your > > conditional. When $x is initialized to 0, the if will return true, > > and you > > will output the very first tr...same at the end...so i'd have > > something like > > this: > > > > <table width="450" border="1" align="center"> > > <!-- we delete this first <tr> //--> > > <? > > $x = 0; > > #different here for later reason > > $length = 42; > > while ($x <= $length) > > { > > $x++; > > if ($x % 5 == 0) > > { > > echo "<tr>\n"; > > } > > echo "<td>".$x."</td>\n"; > > if ($x % 5 == 0) > > { > > echo "</tr>\n"; > > } > > > > } > > > > #also added in > > if($length % 5 != 0){ > > { > > #then we know that it did not end completely, so echo > > you're final </tr> > > echo "</TR>\n"; > > } > > #no need for an else block because it would do nothing > > ?> > > <!-- as well as this one </tr> //--> > > </table> > > > > Now if it ends on a complete row, you're fine! > > > > problem 1: what about if it ends at 42 or something, with just a > > closing</td>? > > solution: make a final check to see if you need that closing </tr> > > That is the if statement after you're loop... > > > > I hope this helps. > > > > -jack > > > > > > > > -----Original Message----- > > From: Jerry Lake [mailto:jerryl@europa.com] > > Sent: Thursday, April 26, 2001 2:32 PM > > To: php-general@lists.php.net > > Subject: [PHP] cell iterations in loop > > > > > > I've got some code that I am > > creating that creates a table with > > a loop. and it works fine for what > > it is, but my question is how do I > > compensate for rows that aren't divisible > > by 5 ? i.e. the empty cells at the table. > > additionally if it ends on a complete row > > (divisible by 5) I end up with an additional > > empty row at the end of the table, I can > > see why it does, I'm just trying to get around > > it. no big hurry on this, I'm just trying to > > learn more. > > > > <snip> > > <table width="450" border="1" align="center"> > > <tr> > > <? > > $x = 0; > > while ($x <= 42) > > { > > $x++; > > if ($x % 5 == 0) > > { > > echo "<td>".$x."</td>\n"; > > echo "</tr>\n<tr>\n"; > > } > > else > > { > > echo "<td>".$x."</td>\n"; > > } > > } > > ?> > > </tr> > > </table> > > </snip> > > > > Jerry Lake - jerryl@europa.com > > Interface Engineering Technician > > Europa Communications - http://www.europa.com > > Pacifier Online - http://www.pacifier.com > > > > > > -- > > 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 > > > > > > > > -- > > 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 > > > > > > -- > 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 > > > -- > 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 >

« previous php.general (#50525) next »