Drop Down Menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Drop Down Menu

Post by SidewinderX »

Hello, I guess im trying to populate a drop down menu with a variable, the script I wrote is pretty simple

<?php
for ($i = 8; $i <=64; $i+=2){
print "$i <br>\n";
}
?>

Which of course starts at 8 and goes to 64 by 2 in other words 8, 10, 12, 14....and so on

Now my question is how do I put those numbers ($i) into a drop down menu. Ive tried all sorts of syntax but usually it either dosent work at all, prints all the numbers on one line, or prints '66' only.
Any help is appreciated.

Thanks,
~~~Sidewinder~~~
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

$output = '<select name="something">';
for($i = 8; $i <= 64; $i += 2)
{
  $output .= '<option value="'.$i.'">'.$i.'</option>';
}
$output .= '</select>';

echo $output;

?>
Post Reply