html form: using sql row for select option

Discussion in 'PHP' started by bobocheez, Aug 29, 2009.

  1. #1
    Hi, I have the following code and I want it to show a dropdown list from slq rows. However, it does not work. How should this be formatted?
    Thanks

     
    <?php
    include('config.php');
    $query = "SELECT * FROM subcategories ORDER BY cat_id ASC";
    $result = mysql_query($query) or die('Sorry, could not access the database');
    mysql_num_rows($result);
    $subcat_id = $row['subcat_id'];
    $subcat = $row['subcategorie_name'];
    $cat_id = $row['cat_id'];
    ?>
    <form action="addchan2.php" method="post">
     <select name="subcat">
     <?php while($row=mysql_fetch_array($result, MYSQL_ASSOC))
       {
           $cat = $row['cat'];
         echo "<option value=\"$subcat\">$subcat</option>";
       } ?>
     </select>
    <input type="text" name="chan">
    <input type="text" name="subcat_id" value="<?echo"$subcat_id";?>">
    <input type="text" name="cat_id" value="<?echo"$cat_id";?>">
    <input type="submit" value="Add">
    </form>
    
    PHP:

     
    bobocheez, Aug 29, 2009 IP
  2. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    oh, nevermind, i had to add the arrays after the while statement
     
    bobocheez, Aug 29, 2009 IP