[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

Drop Down loading slowly

My php populated drop down loads exceptionally slowly.

The code is in the form.  I also tried to assign it to a variable at the top of the page and then echo the variable at the correct point in the form, but that didn't change the speed.

<select name="year" style="width: 70px;">
                                   	<option>Year</option>  
<?php 
		$current_year = Date("Y");
		$year_dropdown = '';
		$selected = '';
		for ($i = ($current_year - 80); $i <= ($current_year); $i++) {
			if(isset($trimmed['year']) && ($trimmed['year'] == $i)) 
							  $selected = ' selected="selected" ';
			$year_dropdown .= '<option ' . $selected . 'value="'. $i . '">' . $i . '</option>';
		}
?>
</select>

Open in new window


Suggestions on how to speed it up?
0
christamcc
Asked:
christamcc
1 Solution
 
christamccAuthor Commented:
I just rewrote the code and it works much faster now!

<select name="year" style="width: 70px;">
   <option>Year</option>  
   <?php 
	 $current_year = date("Y");
	$last_year = ($current_year - 75);
	$year_dropdown = '';
	$selected = '';
	echo  $current_year . $last_year;
	if(!isset($trimmed['year'])) {$trimmed['year'] = "Year";} 
											
	for ($i = $last_year; $i <= ($current_year); $i++) {
		if($trimmed['year'] == $i) 
		{$selected = ' selected="selected" ';}
		$year_dropdown .= '<option ' . $selected . 'value="'. $i . '">' . $i . '</option>';
	}
	echo $year_dropdown;
        ?>
          </select>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now