SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot soart's Avatar
    Join Date
    Nov 2003
    Location
    Norwich UK
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Building a select statement but...

    the required values are not appearing in a select drop down


    code
    PHP Code:
       <td width="56%"><form name="form3" method="post" action="">
        <?php
             
    for($i $std$i <= $dmth$i++){
             
    $opts = array($i); 
             
    $value $i;
             
    $name $i;//print_r($i);
                               
    }
             echo 
    "<select name='select3'>";
             foreach(
    $opts as $opt){
             
    $selected "SELECTED";
             }
             echo 
    "<option value='" .$opt["value"] . "' $selected>";
             echo 
    $opt["name"];
             echo 
    "</option>";
            echo 
    "</select>";?>      
          </form></td>
    what I want to end up with is a drop down select starting at the number set by $std and finishing with the number set by $dmth...where am I going wrong please?

  2. #2
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoa, quite a few mistakes there - look at the following code which will do what you want and then ask if you have any questions about it. Might be easier than debugging what you posted

    PHP Code:
    <form>
    <select name="select3">
    <?php
        $start 
    1;
        
    $end 20;
        
        for (
    $i $start$i <= $end$i++)
        {
            echo 
    "<option>$i</option>";
        }
    ?>
    </select>
    </form>
    Cheers,

    Rich
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •