for($i=1;$i<=50;$i++) { if ((!empty($content) && $row[$content] == $states[$i]) || ($dstate == $states[$i])) $selected="SELECTED"; else $selected=""; printf("<option value=\"%s\" %s>%s</option>", $states[$i], $selected, $nstates[$i]); }
I always prefer to use printf to mix content and data. And why not use the || your reaching a single solution Jerry Verhoef >-----Original Message----- >From: Joffrey van Wageningen [mailto:[EMAIL PROTECTED]] >Sent: Friday, February 15, 2002 10:00 AM >To: PHP Email List >Subject: Re: [PHP] Looking for optimal coding > > > > > This is not a big thing. > > But I am looking at this thinking there is a way to make the code take >up > > even less lines. > > > for($i=01;$i<=50;$i++) { > > if (!empty($content)) { > > if ($row[$content]==$states[$i]) > > echo "<option value=\"$states[$i]\" > > selected>$nstates[$i]\n"; > > else > > echo "<option >value=\"$states[$i]\">$nstates[$i]\n"; > > } > > else { > > if ($dstate == $states[$i]) > > echo "<option value=\"$states[$i]\" > > selected>$nstates[$i]\n"; > > else > > echo "<option >value=\"$states[$i]\">$nstates[$i]\n"; > > } > > } > >i would try: > >for($i=01;$i<=50;$i++) { > if(!empty($content) && $row[$content] == $states[$i]) > $selected = " selected"; > elseif($dstate == $states[$i]) > $selected = " selected"; > else > $selected = ""; > echo "<option >value=\"".$states[$i]."\"".$selected.">".$nstates[$i]."</option>"; >} > >trading four echo's for a one echo and a extra var and nest the ifs > > > Basically I want to check for two possible conditions to make an item >selected. > > If the first one is valid then do not check for the other. > > > > Get what I mean? > > Any expert programmers out there with the way to chop this even further? > >test it :) > >mvgr, >Joffrey van Wageningen > >-- >.-[ Joffrey van Wageningen | WoLFjuh | [EMAIL PROTECTED] ]-------------- >| Networking Event 2000 - www.ne2000.nl - IRCnet:#ne2000, Undernet:#clue >| PGP:1024D/C6BA5863 - 3B93 52D3 CB91 9CB7 C50D FA79 865F 628A C6BA 5863 >| * We demand guaranteed rigidly defined areas of doubt and uncertainty. >| -- Douglas Adams > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > _________________________________________________________________ Chat on line met vrienden en probeer MSN Messenger uit: http://messenger.msn.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php