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
Hi all, we have some important news to share. Please follow the link here to find out more!

https://www.boards.ie/discussion/2058419143/important-news/p1?new=1

PHP Populate Drop Down Menu

  • 05-03-2008 06:27PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 357 ✭✭apoch632


    Yeah.

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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭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