0

$result123=mysql_query("select *from semdropdown");

       <td><label for="textfield8">Semester </label></td>
      <td colspan="3"><select name="semester" value="<?php echo $semesterid; ?>">
           <option value="">Select Semester</option>

           <?php
      while($row123 = mysql_fetch_array($result123))
  {
      if($semesterid  == $row123[semesterid])
      {
          $selvar = "selected";
      }
  echo "<option value='$row123[semesterid]' ". $selvar . ">$row123[semesterkey]</option>";
  $selvar ="";
  }

  ?>
          </select>
        </p>
          <p></p></td>
    </tr>



 $result123=mysql_query("select *from semdropdown");
<tr>
       <td><label for="textfield8">Semester </label></td>
      <td colspan="3"><select name="semester" value="<?php echo $semesterid; ?>">
           <option value="">Select Semester</option>

           <?php
      while($row123 = mysql_fetch_array($result123))
  {
      if($semesterid  == $row123[semesterid])
      {
          $selvar = "selected";
      }
  echo "<option value='$row123[semesterid]' ". $selvar . ">$row123[semesterkey]</option>";
  $selvar ="";
  }

  ?>
          </select>
        </p>
          <p></p></td>
    </tr>
2
Contributors
5
Replies
16
Views
3 Years
Discussion Span
Last Post by sql_1
0

hi ,i have a problem to display the selected value of dropdown in the same dropdown box after submit...
here is my code...plz help..thanks in advance .....:-) (the code display always Select Semester * instead of selected item)
for example if i select *third semester
the code display *Select Semester * after submission ..plz hlp me frnz)

table semdropdown structure::

semesterid semesterkey
1 First Semester
2 Second Semester
3 Third Semester
4 Fourth Semester
5 Fifth Semester
6 Sixth Semester
7 Seventh Semester
8 Eighth Semester

Edited by sql_1

0

here is my code::(plz hlp me)

$result123=mysql_query("select *from semdropdown");

       <td><label for="textfield8">Semester </label></td>
      <td colspan="3"><select name="semester" value="<?php echo $semesterid; ?>">
           <option value="">Select Semester</option>
           <?php
      while($row123 = mysql_fetch_array($result123))
  {
      if($semesterid  == $row123[semesterid])
      {
          $selvar = "selected";
      }
  echo "<option value='$row123[semesterid]' ". $selvar . ">$row123[semesterkey]</option>";
  $selvar ="";
  }
  ?>
          </select>
        </p>
          <p></p></td>
    </tr>
 $result123=mysql_query("select *from semdropdown");
<tr>
       <td><label for="textfield8">Semester </label></td>
      <td colspan="3"><select name="semester" value="<?php echo $semesterid; ?>">
           <option value="">Select Semester</option>
           <?php
      while($row123 = mysql_fetch_array($result123))
  {
      if($semesterid  == $row123[semesterid])
      {
          $selvar = "selected";
      }
  echo "<option value='$row123[semesterid]' ". $selvar . ">$row123[semesterkey]</option>";
  $selvar ="";
  }
  ?>
          </select>
        </p>
          <p></p></td>
    </tr>
0

Where is the value of $semesterid being set and why are you repeating the same code twice for your query and dropdown?

0

by mistake i paste the query 2 times...thanks for the replay dude.....i solve the problem

0

i found this code and it worked

<?php $options = array( 1=>'General Question', 'Company Information', 'Customer Issue', 'Supplier Issue', 'Supplier Issue', 'Request For Quote', 'Other' );
$topic = $_REQUEST['topic'];  ?>  
<select name="topic" style="margin-bottom:3px;">  
<?php foreach ( $options as $i=>$opt ) : ?>      
<option value="<?php echo $i?>" <?php echo $i == $topic ? 'selected' : ''?>><?php echo $opt ?></option>     
<?php endforeach; ?> </select>
This topic has been dead for over six months. 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.