PHP从mysql填充下拉列表并获取ID

I have tried to search StackOverlow (and google) but cant find what i am looking for.

Basically i need to get an list of id and text from an mysql table.

Table:

ID: 1 - Text: Title1 ID: 2 - Text: Title2 etc.

But i want it to populate the dropdown with the text, and when I select an item in the dropdown, it gives me the ID of that text (string or int).

So if I select the Title2, it should give me 2

<?
include 'db.php';

$query="SELECT topic_id,topic FROM help_topic WHERE isactive=1 ORDER BY topic";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<select name=category value='' id=category></option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[topic_id]>$nt[topic]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box

?>

Use a loop to generate those values

<select>
<?php foreach ( $table_objects as $object){
   echo '<option value="'.$object['id'].'">'.$object['text'].'</option>';
}
?>
</select>