RE: [PHP-DB] Current row of query

From: Date: Thu, 26 Sep 2002 15:41:34 +0000
Subject: RE: [PHP-DB] Current row of query
Groups: php.db 
Request: Send a blank email to php-db+get-22014@lists.php.net to get a copy of this message
> -----Original Message----- > From: Patrick Lebon [mailto:patrick@webation.com] > Sent: 26 September 2002 16:20 > > This is how im currently doing it... > > $rowNum = 0; > while ( $row = mysql_fetch_array($result) ) > { > $rowNum++; > if ($rowNum % 2) { $bgCol = "#EADBC6"; } else { $bgCol = "#EFE1CE"; } > echo "......"; > } Looks like a good 'un to me, although I wonder why you're incrementing $rowNum and then doing a separate access to it, when the ++ operator is designed precisely to avoid the need for this; the following is identical in functionality to the above: $rowNum = 0; while ( $row = mysql_fetch_array($result) ) { if ($rowNum++ % 2) { $bgCol = "#EADBC6"; } else { $bgCol = "#EFE1CE"; } echo "......"; } And, having got this far, I'd probably then go on to rewrite the if line using the ?: operator instead: $bgCol = ($rowNum++ % 2) ? "#EADBC6" : "#EFE1CE"; 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.db (#22014) next »