Jump to content

Drop Down


dudejma

Recommended Posts

The code for the drop down:

 

echo '<select name="select"  ONCHANGE="goto(this.form)">';
					while ($dropDown > 0) {
					if ($page == $dropDown) {
					$selected = 'selected="selected"';
					} else {
					$selected = "";
					}
					echo "<option value=\"searchFlights.php?page=" . $dropDown . "\" $selected>" . $dropDown . "</option>";
					$dropDown = $dropDown - 1;
					}			
					echo '</select>';

 

It works fine, but I want 1 to be at the top of the list and go down from there because right now, it starts with the biggest number and goes down. Any suggestions? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/255071-drop-down/
Share on other sites

OK, I'm going to make some assumptions with this. If there are (for argument's sake) 275 records, and you want 30 per page, you're probably doing something like this. Also, if you're actually using round(), you can lose a page of records, so it's appropriate to use ceil instead.

 

$records = 275; // result of COUNT() query, or mysql_num_rows()
$per_page = 30; // divisor
$pages = ceil( 275 / 30 );

 

Then once you have the number of pages you need, you can use a for loop, starting with the lowest value, incrementing the number on each iteration. This should give you the information you need to implement it.

 

echo "<select name=\"select\">\n";
for( $i = 1; $i < $pages; $i++ ) {
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select>\n";

 

Link to comment
https://forums.phpfreaks.com/topic/255071-drop-down/#findComment-1307898
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.