PHP populate dropdown from mysql and get ID -


i have tried search stackoverlow (and google) cant find looking for.

basically need list of id , text mysql table.

table:

id: 1 - text: title1 id: 2 - text: title2 etc.

but want populate dropdown text, , when select item in dropdown, gives me id of text (string or int).

so if select title2, should give me 2

<? include 'db.php';  $query="select topic_id,topic help_topic isactive=1 order topic"; /* can add order clause sql statement if names displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=category value='' id=category></option>"; // printing 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 added looping through array */ } echo "</select>";// closing of list box  ?> 

use loop generate values

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

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -