Creating dropdown from mySQL info?

Discussion in 'PHP' started by mokimofiki, Aug 25, 2008.

  1. #1
    The code below is supposed to display a dropdown option box with the information in the table series that has the information in the series column ... of course it is not working any help would be great thank you.

    ALSO: my connection to the db is fine the problem is in the source below somewhere :)

    <?php 
    $result = mysql_query("SELECT series FROM series");
    print "<select name=series> \n";
    print "<option></option>";
    while($row = mysql_fetch_assoc($result))
    {
    print "<option value = $row[series]</option> \n";
    }
    print "</select> \n"; 
    ?>
    Code (markup):
     
    mokimofiki, Aug 25, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try replacing:
    print "<option value = $row[series]</option> \n";
    PHP:
    With
    print "<option value=\"{$row['series']}\">{$row['series']}</option> \n";
    PHP:
    If that doesn't work, please paste the entire HTML output as sometimes MySQL Errors are within the <select>, so aren't displayed.

    Jay
     
    jayshah, Aug 25, 2008 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Okay I replaced my code with your suggestion above and the html output is:

    <select name=series> 
    <option></option>
    <option value=""></option> 
    <option value=""></option> 
    <option value=""></option> 
    <option value=""></option> 
    <option value=""></option> 
    </select>
    Code (markup):
    Its also displaying the correct number of options they are just empty?!

    if I just echo whats in the mySQL table it displays fine but trying to get it into the dropdown seems to be very irritating :)
     
    mokimofiki, Aug 25, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Please add:
    var_dump($row);
    PHP:
    Under the your while($row = ...){ line, and paste that output.

    Jay
     
    jayshah, Aug 25, 2008 IP
    mokimofiki likes this.
  5. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Thank you that seems to have worked

    I appriciate all of your help :)
     
    mokimofiki, Aug 25, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Really? :D

    It should just dump $row, not into a <option> or anything. Thanks for the rep. and let me know if you need anything :eek:

    Jay
     
    jayshah, Aug 25, 2008 IP
  7. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #7
    I added before the while($row ... so i assume somewhere else in my page row is used and never released. Np rep definatly deserved thank you again :)
     
    mokimofiki, Aug 25, 2008 IP