RE: [PHP] More brain farts

From: Date: Tue, 06 Aug 2002 16:27:25 +0000
Subject: RE: [PHP] More brain farts
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111394@lists.php.net to get a copy of this message
I realize that the 2 are the same, that's just were I left off... As far as the counter, I could go either way on that, no preference, thanks for the suggestion. As you can see adding <tr>'s to one of the statements will cause nesting problems because of the <tr> outside the while loop. Removing the outside tr and adding it inside only will also not produce the desired effect. I need to get it to do: <tr><td>image1</td><td>image2</td><td>image3</td><td>image4</td></tr> <tr><td>image1</td><td>image2</td><td>image3</td><td>image4</td></tr> etc... > -----Original Message----- > From: Ford, Mike [LSS] [mailto:M.Ford@lmu.ac.uk] > Sent: Tuesday, August 06, 2002 12:02 PM > To: 'Brian V Bonini'; PHP Lists > Subject: RE: [PHP] More brain farts > > > > -----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

« previous php.general (#111394) next »