Jump to content

Recommended Posts

Hi I am a newbie programmer and I am stuck with this problem. I need to populate a form (text boxes) when the user selects a value from a dropdown box. here is the code that I am populating the dropdown box with
<?php
$sql = "select extension from role";
$Pass = $db->query($sql);

echo '<tr><td>View Roles :</td><td><select name="role">';
while($Pass->fetchInto($row)){
$id = $row[0];
echo '<option name="role"value='.$id.'>'.$id.'</option>';
}
echo '</select>';
?>
here is the mysql data base that i need to populate the textboxes with the extension field is the dropdown box values. I need it so when a user clicks the dropdown box and chooses a extension it fills the textboxes with everything on that row. Any Help Thanks
+-----------+------+--------+
| extension | dnd  | paging |
+-----------+------+--------+
| default  | off  | on    |
| trial    | off  | on    |
| test      | off  | on    |
| test3    | off  | on    |
+-----------+------+--------+
[code]<?php
      $sql = "select extension from role";
      $Pass = $db->query($sql);
     
      echo '<tr><td>View Roles :</td><td><select name="role">';
      while($Pass->fetchInto($row)){
      $id = $row[0];
        echo '<option name="role"value='.$id.'>'.$id.'</option>';
      }
      echo '</select>';     
?>  [/code]
for one try reformatting the code, see if that helps
[code]<?php
      $sql = "select extension from role";
      $Pass = $db->query($sql);
     
      echo "<tr><td>View Roles :</td><td><select name=\"role\">";
      while($Pass->fetchInto($row)){
      $id = $row[0];
        echo "<option name=\"role\" value=\"{$id}\">{$id}</option>";
      }
      echo "</select>";     
?>  [/code]
if that doesn't work say what is happening, is the value just turning up blank.
Try this:
[code]
<?php
$query = "SELECT extension FROM table ORDER BY";
$result = mysql_query($query);
print "<SELECT name=extension><option>Choose Extension</option>";
while ($row = mysql_fetch_assoc($result))
    {
        echo  "<option value='{$row['extension']}'>{$row['extension]}</option>";
    }
    mysql_close($link);
print "</SELECT>";
?>
[/code]

Make sure to change "table" to the table where the extension is located.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.