0

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  ";
}
?>
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by heshanm
0

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>
0

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..:-)

Edited by heshanm

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.