Gayner Posted August 8, 2009 Share Posted August 8, 2009 This code: $styles = array(); $d = dir('css'); while (($entry = $d->read()) !== false) { if (substr($entry, strlen($entry)-4) == '.css') $styles[] = substr($entry, 0, strlen($entry)-4); } $d->close(); // Only display the style selection box if there's more than one style available if (count($styles) == 1) echo "\t\t\t".'<div><input type="hidden" name="skinstyle" value="'.$styles[0].'" /></div>'."\n"; else if (count($styles) > 1) { natsort($styles); ?> <form action="index.php?auth_key=<?php echo $Profile['key']; ?>" method="post" name='theForm' onsubmit='return ValidateProfile()'> Select your Forum Style: <select name="skinstyle"> <?php while (list(, $temp) = @each($styles)) { if ($user['skinstyle'] == $temp) echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n"; else echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n"; } ?> </select> <?php } Or: using this as PHP: ($Profile['skinstyle']=='0')? $i = "selected":""; ($Profile['skinstyle']=='1')? $i1 = "selected":"";($Profile['skinstyle']=='2')? $i2 = "selected":""; ($Profile['skinstyle']=='3')? $i3 = "selected":"";($Profile['skinstyle']=='4')? $i4 = "selected":"";($Profile['skinstyle']=='5')? $i5 = "selected":"";($Profile['skinstyle']=='6')? $i6 = "selected":""; ($Profile['skinstyle']=='7')? $i7 = "selected":""; AND HTML FOR THAT: <select name="skinstyle"> <option value="0" $i>24-7GT Default</option> <option value="1" $i1>Light Blue</option> <option value="2" $i2>Sunset</option> <option value="3" $i3>Beautiful Blue</option> <option value="4" $i4>Tan</option> <option value="5" $i5>Crazy Gray</option> <option value="6" $i6>Toxin</option> </select> Which one is better? I created both btw.. but I created the second code first.. I recently made the top code so now I dont know which is better.. thanks Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 I'd keep it as you have it now while (list(, $temp) = @each($styles)) { if ($user['skinstyle'] == $temp) echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n"; else echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n"; } That is much more easer to read/maintain than this. This is why loops where invented ($Profile['skinstyle']=='0')? $i = "selected":""; ($Profile['skinstyle']=='1')? $i1 = "selected":"";($Profile['skinstyle']=='2')? $i2 = "selected":""; ($Profile['skinstyle']=='3')? $i3 = "selected":"";($Profile['skinstyle']=='4')? $i4 = "selected":"";($Profile['skinstyle']=='5')? $i5 = "selected":"";($Profile['skinstyle']=='6')? $i6 = "selected":""; ($Profile['skinstyle']=='7')? $i7 = "selected":""; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.