Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    A listbox Question

    I have a page that is pulling things out a database like for instance country_name, the name of my table is country...and I have 2 columns called country_ID, and Country_Name;
    I have 4 rows called US, Canada, Mexico, and Spain
    I was wondering where my error was in displaying the items in the listbox/combo box
    I connect to a database in PHPmyAdmin and pull the information out of the database and want to display it in a listbox here is my code
    <?php
    $db = mysql_connect("localhost", "username", "pw")or die(mysql_error());

    mysql_select_db("DatabaseName")or die(mysql_error());

    $options = mysql_query("SELECT * FROM country");
    $options=mysql_fetch_array($options);

    function enhanced_list_box($options){
    $sql = "select " . options['id_field'];
    $sql .= ", " . $options['value_field'];
    $sql .= " from " . $options['table'];

    /* append any where criteria to the sql */
    if (isset($options['where_statement'])) {
    $sql .= " where " . $otpions['where_statement'];

    }

    /* set the sort order of the list*/

    $sql .= " order by " . $options['value_field'];

    $result = mysql_query($sql) or die("error in SQL);

    echo '<select name="', $options['id_field'], '" size="1">';

    while ($row = mysql_fetch_array($result, MYSQL_NUM))
    {
    if ($row[0] == $options['highlight_id']) {
    echo '<option value="', $row[0], '" SELECTED>', $row[1], '</option>';
    }
    }

    echo '</select>';

    }
    ?>
    <html>
    <head
    </head>
    <title><? echo $obj[1] ?></title>

    <? enhanced_list_box(array(
    'table' => 'country',
    'id_field' => 'country_id',
    'value_field' => 'country_name',
    hightlight_id = 4));
    ?>
    <body>
    </body>
    </html>
    this is my error
    Parse error: parse error in /home/briintex1/public_html/index.php on line 10
    thanks
    bri

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,094
    Thanks
    11
    Thanked 101 Times in 99 Posts
    $sql = "select " . options['id_field'];

    should be

    $sql = "select " . $options['id_field'];
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    thanks

    thanks that was it...I should have caught that..
    thanks again
    thanks
    bri


  •  

    Posting Permissions

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