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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2005
    Location
    Steger, IL
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question populate drop down from mysql with php part II

    I have this working sort of, but I still can't figure out why it is skipping the "uniqid" field. Does it not work if the field is an auto_incrementing INT value or something?

    Also, where do I add the "form action" elements to this code to allow the user to actually submit after selecting?

    PHP Code:
    <?php

    //connect to MySQL

    $connect mysql_connect("localhost","xxx","xxx") or
    die (
    "Could not connect to database.");

    //choose the database

    mysql_select_db("peoplelist");

    //get data from database

    $query mysql_query(
        
    "SELECT `uniqid`,
                `firstname`,
                `lastname`
           FROM `people`
       ORDER BY `lastname` ASC"
    ) or die (mysql_error());

    echo 
    "<select name='people'>\n";

    while (
    $data mysql_fetch_array($queryMYSQL_ASSOC))
    {
        echo 
    "    <option value='{$data['uniqid']}'>{$data['lastname']},
    {$data['firstname']}</option>\n"
    ;
    }

    echo 
    "</select>\n";

    ?>
    Jim

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    I have this working sort of, but I still can't figure out why it is skipping the "uniqid" field. Does it not work if the field is an auto_incrementing INT value or something?

    Also, where do I add the "form action" elements to this code to allow the user to actually submit after selecting?
    didnt test this or anything but see if it works better for you:


    PHP Code:
    echo "<form name='form1' method='post' action='script.php'>\n";

    echo 
    "<select name='people'>\n";

    while (
    $data mysql_fetch_assoc($query))
    {
        echo 
    "<option value='".$data['uniqid']."'>".$data['lastname'].",".$data['firstname']."</option>\n";
    }

    echo 
    "</select>\n"

    echo 
    "<input type='submit' name='submit' value='Submit'>\n";

    echo 
    "</form>\n"
    Last edited by chump2877; 06-25-2006 at 06:10 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    Sep 2005
    Location
    Steger, IL
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked great!

    One more problem to solve then I am good to go I think. Most of this stuff can all be recycled and used over and over thoughout the application once it actually works correctly, but I still can't figure out why the crop down completely ignores the "uniqid" when populating from the database...
    Jim

  • #4
    New Coder
    Join Date
    Sep 2005
    Location
    Steger, IL
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I know what is wrong with this, but I don't know the syntax of how to fix it. I have to comvert the uniqid value from an INT to CHAR or VARCHAR so it will work. Any suggestions?

    Thanks,

    Jim
    Jim


  •  

    Posting Permissions

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