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

Recommended Answers

All 5 Replies

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

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>

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

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

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