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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    Italy
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    drop down list box using data from MySQL

    Hi
    I've been trying to create a drop down list box using data from MySQL table. Mysql table is "ihs" and the field to be listed is "Bloom_Name", can someone tell me what's wrong with the code below and if possible tell me how to fix it.
    Thank JD


    <?PHP
    mysql_connect("localhost", "xxx_xx", "xxxx") or die(mysql_error());
    mysql_select_db("xxxx_xxx") or die(mysql_error());
    $query="SELECT Bloom_Name FROM ihs";
    $result = mysql_query ($query);
    echo "<select name=ihs value=''>Bloom_Name</option>";
    while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
    echo "<option value=$nt[id]>$nt[name]</option>";
    /* Option values are added by looping through the array */
    }
    echo "</select>";// Closing of list box
    ?>

  • #2
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi, i had the same problem a few weeks ago, but i managed to sort it out, here is what i used.

    <?php

    require ('database.php');//connection to database

    $query = "select scriptname from weblink.script_summary where scriptname='$scriptname'";

    $result = mysql_query ($query) or die (mysql_error());

    echo "<td><b>Please Select A SCRIPT:</b></td> <td><SELECT name=\"scriptname\">";

    if (mysql_num_rows($result)>0)

    {

    while($row=mysql_fetch_array($result))

    {

    echo "<option value=\"$row[scriptname]\">$row[scriptname]</option>";

    }

    }

    echo "</SELECT></td>";

    ?>

    hope this helps.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    mysql_connect
    ("localhost""xxx_xx""xxxx") or die(mysql_error());
    mysql_select_db("xxxx_xxx") or die(mysql_error());
    $query="SELECT Bloom_Name FROM ihs";
    $result mysql_query($query);

    echo 
    '<select name="ihs">';
        while(
    $nt=mysql_fetch_array($result)){ //Array or records stored in $nt
            
    echo '<option value="' $nt['id'] . '">' $nt['name'] . '</option>';
            
    /* Option values are added by looping through the array */
        
    }
    echo 
    '</select>'// Closing of list box 
    ?>
    try that or post your error messages

  • #4
    New Coder
    Join Date
    Jan 2003
    Location
    Italy
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi
    I've tried your code, but all I get is an empty drop menu.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $query="SELECT Bloom_Name FROM ihs"
    You need to select the fields from the table
    PHP Code:
    $query="SELECT id, name, FROM ihs"
    or
    PHP Code:
    $query="SELECT * FROM ihs"
    or depending on your database setup
    PHP Code:
    $query="SELECT id, name, FROM Bloom_Name"

  • #6
    New Coder
    Join Date
    Jan 2003
    Location
    Italy
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi
    I'm new at this, I guess you figure that out.
    below is mysql database.

    LOCK TABLES `ihs` WRITE;
    INSERT INTO `ihs` (`id`, `Bloom_Name`, `Pod_Parent`,

    what I want to list on the drop menu is Bloom_Name what would the id be?
    can you please write me the code
    Thank you so much

  • #7
    New Coder
    Join Date
    Jan 2003
    Location
    Italy
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much, I got it running ok.

  • #8
    New Coder
    Join Date
    Jan 2003
    Location
    Italy
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How can I add on change command on the php script?

    <select name="select"onChange=" Hybridiser.value=this.options[this.selectedIndex].text"
    size="1">

    <?php
    mysql_connect("localhost", "xxxx_xx", "xxx") or die(mysql_error());
    mysql_select_db("xxxx_xxx") or die(mysql_error());
    $query="SELECT Bloom_Name FROM ihs";
    $result = mysql_query($query);

    echo '<select name="ihs">';
    while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
    echo '<option value="' . $nt['id'] . '">' . $nt['Bloom_Name'] . '</option>';
    /* Option values are added by looping through the array */
    }
    echo '</select>'; // Closing of list box
    ?>

  • #9
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onchange="this.form.submit()"

    PHP Code:
    <?php 
    mysql_connect
    ("localhost""xxxx_xx""xxx") or die(mysql_error()); 
    mysql_select_db("xxxx_xxx") or die(mysql_error()); 
    $query="SELECT Bloom_Name FROM ihs"
    $result mysql_query($query); 

    echo 
    '<select name="ihs" onchange="this.form.submit()">'
    while(
    $nt=mysql_fetch_array($result)){ //Array or records stored in $nt 
    echo '<option value="' $nt['id'] . '">' $nt['Bloom_Name'] . '</option>'
    /* Option values are added by looping through the array */ 

    echo 
    '</select>'// Closing of list box 
    ?>


  •  

    Posting Permissions

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