0

I HAVE ONE FORM IN THIS I AM INSERTING AND UPDATIONG BOTH, I WANT TO RETAIN the value of combox box when php validations occurs

<td>Page Id</td>
      <td><select name='pageID' class="select">
          <option  value='0' >select any page</option>
          <?php

$sql10 = "SELECT ID,Title FROM page";
$val=$PageId?:'';
$rs = mysql_query($sql10) or die(mysql_error());
while($row = mysql_fetch_array($rs)){
$selected = ($val == $row['ID'] ? 'selected="selected"' : '');
echo '<option value ="' . $row['ID'] . '" '. $selected .'>' . $row['Title'] . '</option>';
}

want that if php validation ouccur the value of the combox still not changed

2
Contributors
1
Reply
21
Views
3 Years
Discussion Span
Last Post by Webville312
0

You can use the code below. Replace the respective values with the ones that apply to your code.

<select name="pageId">
                <?php
                    // I used the $_GET method. You could be using $_POST
                    $subject_id = $_GET['subject_id'];

                    // display a drop down of all categories with the chosen category preselected
                    $query = mysql_query("SELECT * FROM subjects WHERE subject_id = '$subject_id'");
                    while ($row = mysql_fetch_assoc($query)) 
                    {
                        $sub_id = $row['subject_id'];
                        $subject_name = $row['subject'];

                        if ($sub_id == $subject_id) 
                        {
                            $selected = "selected='selected'";
                        }
                        else
                        {
                            $selected = "selected = 'none'";
                        }

                        echo "<option value='$subject_name' $selected>$subject_name</option>\n";
                    }

                ?>
                </select>

Edited by Webville312

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.