Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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