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