Drop Down List using PHP from database HELPPPP

Discussion in 'PHP' started by prajita, Oct 26, 2007.

  1. #1
    Hi,

    This is my first time here in the forum. i hope i will get some help.

    Here is my code

    $results_id = @mysql_query($query, $connect)
    or die('query error: ' . mysql_error());
    print '<select name=\"studentid"\>';
    while($row = mysql_fetch_row($results_id));
    { $count1=count($row);
    for($i=0; $i<=count1; $i=$i+1)
    {
    print '$row[$i]';
    }
    }

    print '</select>';

    I am kinds new to php and i dont know what wron did i do in the code above . i wanted to create a dropdown list form the values in a table in a database.

    lets say

    table name: student
    that has student id and student name

    I have no freaking idea how to do it.

    Your help will be appreciated
     
    prajita, Oct 26, 2007 IP
  2. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I'll give you a hint. :)

    Look at the HTML source for a working drop down box. Compare that to the output your code has.

    You're really close just missing a couple of tags.
     
    tandac, Oct 26, 2007 IP
  3. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $results_id = @mysql_query($query, $connect);
    echo "<select name=\"studentid\">";
    while($row = mysql_fetch_row($results_id));
    {
    echo "<option value=\"".$row['id']."\">".$row['student_name']."</option>";
    }
    echo "</select>";
     
    grikis, Oct 27, 2007 IP
  4. prajita

    prajita Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    echo "<select name=\"studentid\">";
    while($row = mysql_fetch_row($results_id));
    {
    echo "<option value=\"".$row['stu_id']."\">".$row['stu_id']."</option>";
    }
    echo "</select>";


    print '</select>';

    In above code i am trying to create a drop down list from a data in a table in a database

    The name of the field in table is stu_id


    Please help

    I really need your help
     
    prajita, Oct 27, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Use mysql_fetch_array() or mysql_fetch_assoc() instead of mysql_fetch_row()
     
    nico_swd, Oct 27, 2007 IP