Hi All,

I want to add data for the time tables. I have created 3 fields namely grade, class and stream which is only relevant for advanced level classes. otherwise the "stream" field should be disabled. In my database the class table and grade tables were already populated with data. But when i am trying to select from the drop down list no classes were get selected. It automatically selected grade "1" everytime. I have posted my coding. Can anyone show me where i went wrong?

<?php
$grdid=isset($_POST['grade_ID']) ? $_POST['grade_ID'] :'';       
$query="SELECT * FROM grade";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){
if($grdid==$row['grade_id']){   
echo "<option  selected value=\"".$row['grade_id']."\">".$row['grade']."</option> \n  ";
}else{
echo "<option value=\"".$row['grade_id']."\">".$row['grade']."</option> \n  ";
    }
}
?>

          </select></td>
        <td width="1" align="center"> </td>
        <td align="center"><label>Class</label> </td>
        <td width="71">
          <select name="class_ID" id="jumpMenu2" >

<?php
$grdid=isset($_POST['grade_ID']) ? $_POST['grade_ID'] :'';
$query="SELECT class_name FROM class where grade_id='$grdid'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['class_name']."\">".$row['class_name']."</option> \n  ";
}
?>

Recommended Answers

All 2 Replies

This is a copy of the drop down i have used on this site: Click Here

<form id="form" method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
  <select id="sel" name="category">
        <option value="Select">Please select a gallery..</option>
            <?php
                $cxn = mysqli_connect($host,$user,$pword,$db)
                    or die ("Connection failed");
                $query = "SELECT category_id,category_name from gallery_category";
                $result = mysqli_query($cxn,$query)
                    or die ("Query Failed");
             while( $row_1 = mysqli_fetch_array( $result ) )
                {
                    @$photo_category_list .="<option value='$row_1[0]'";
                if ( $_POST["category"] == $row_1[0]) {
                   @$photo_category_list .= " selected";
                    }
                    @$photo_category_list .=">$row_1[1]</option>\n";
                }
                echo $photo_category_list
            ?>
        </select>
        <input name="Submit" type="submit" value="Change Gallery" >
    </form>

Thanks. It helps me to solve the issue. I used the "POST" method to pass the data instead of "GET" method..And now it works..:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.