dudejma Posted January 15, 2012 Share Posted January 15, 2012 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 More sharing options...
Pikachu2000 Posted January 15, 2012 Share Posted January 15, 2012 Where does $dropDown get its initial value? Link to comment https://forums.phpfreaks.com/topic/255071-drop-down/#findComment-1307892 Share on other sites More sharing options...
dudejma Posted January 15, 2012 Author Share Posted January 15, 2012 It counts how many records are in the table and divides it by the number of items per page, then it rounds it. Link to comment https://forums.phpfreaks.com/topic/255071-drop-down/#findComment-1307893 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2012 Share Posted January 15, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.