Jump to content

Which is faster? Or Does it even matter?


Gayner

Recommended Posts

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

Link to comment
Share on other sites

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 :P

($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":"";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.