Simple PHP Problem

Discussion in 'PHP' started by panda46, Oct 5, 2007.

  1. #1
    Hi, I'm just beggining to learn PHP and HTML and I have this problem. I want to make a dynamic roll-down menu, but I dont know how to include <option> in my for cycle, since it's not a php command. Thank You.

    <?php
    $i = 0;
    foreach($vc as $bu ) {
    $i++;
    ?>

    <option value='<?php echo "&nbsp;".$bu['datum']." &nbsp"; ?>'><?php echo "&nbsp;".$bu['datum']." &nbsp"; ?></option>


    </select>
    </form>
    <?php } ?>
     
    panda46, Oct 5, 2007 IP
  2. james_r

    james_r Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure I understand what the problem is, but try this:

    <form action="whatever" method="POST">

    ...

    <select name="xx">

    <?php
    foreach($vc as $bu )
    {
    echo "<option value=\"" . $bu['datum'] . "\">&nbsp;" . $bu['datum'] . "</option>";
    }
    ?>

    </select>

    ...

    </form>
     
    james_r, Oct 5, 2007 IP
  3. loibeignacio

    loibeignacio Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $selected=3;
    echo '<select name="test">';
    	for( $i=1; $i < 101; $i++ ) {
    		$is_sel = ( $i == $selected ) ? 'selected="selected"' : '';
    		echo "<option value=\"$i\" $is_sel>$i</option>\n";
    	}
    echo '</select>';
    PHP:
     
    loibeignacio, Oct 6, 2007 IP
  4. panda46

    panda46 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    worked like charm :) thank you
     
    panda46, Oct 6, 2007 IP