Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP Populate Drop Down Menu

Options
  • 05-03-2008 6:27pm
    #1
    Registered Users Posts: 357 ✭✭


    Hey

    I'm trying to populate a drop down box from a MySQL Database
    Can anyone see whats wrong with this code


    $query="SELECT rate FROM tariff_rate";
    $result=mysql_query($sql);
    
    $options="";
    
    echo $row['rate'];
    
    while ($row=mysql_fetch_array($result)) {
    $options = <option value=".$row['rate'].">"<php? echo ".$row['rate']."?>"</option>;
    }
    


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Few syntax errors and missing tags in there.

    Needs to look like this:
    while ($row=mysql_fetch_array($result)) {
    $options = <option value="<?php echo ".$row['rate']."?>"><?php echo ".$row['rate']."?></option>;
    }
    

    See the difference? :)


  • Registered Users Posts: 357 ✭✭apoch632


    Yeah.

    Its now throwing this error
    Parse error: syntax error, unexpected '<' in blahblah on line 24


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    apoch632 wrote: »
    Yeah.

    Its now throwing this error
    Parse error: syntax error, unexpected '<' in blahblah on line 24
    And what is line 24?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    D'oh, totally read the code wrong.

    Should look like this:
    while ($row=mysql_fetch_array($result)) {
    $options .= "<option value=\"".$row['rate']."\">".$row['rate']."</option>";
    }
    


Advertisement