RE: [PHP] More brain farts
| From: | Ford, Mike [LSS] | Date: | Tue, 06 Aug 2002 16:01:30 +0000 |
| Subject: | RE: [PHP] More brain farts | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111392@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Brian V Bonini [mailto:b-bonini@cox.net]
> Sent: 06 August 2002 16:52
>
> Another one of those thigns I've been staring at too long......
>
> I need to get this to have a new row every 4th cell
>
> <table>
> <tr>
> <?php
> while($row = mysql_fetch_object($result)) {
> $img = $row->image_name;
> if ( ($row->id % 4) == 0) {
> echo "<td><a href=\"/ss/images/$img\"><img
> src=\"/ss/thumbnails/" . $img .
> "\" />" . '</a></td>';
> } else {
> echo "<td><a href=\"/ss/images/$img\"><img
> src=\"/ss/thumbnails/" . $img .
> "\" />" . '</a></td>';
> }
> }
> ?>
> </tr>
> </table>
Well, firstly you've got exactly the same echo statement in both branches of the if, so
there's actually nothing different about the ones with id divisible by 4 -- I suggest you add
an echo "</tr>\n<tr>" in there!
Secondly, can you be absolutely sure that the $row->id values are monotonic increasing? If there
are any gaps, or they are not strictly in order, you'll get bad results -- if there's any
remote chance of this, it would be better to maintain your own counter. It's probably better
practice to do this anyway, as a bit of defensive programming against someone, someday, somewhere
causing your ids to misbehave...!!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211