Log in

View Full Version : Create combo box



tawongunung
05-01-2006, 05:19 AM
hi...
Does anyine can help me, iwant to create combo box on php form, but the it value from table content.

this is my table

table name: country
id---country
1---USA
2---England
3---China
4---Japan
etc..

i'm use Postgre DB

djr33
05-01-2006, 05:27 AM
I'm sorry, but I don't quite understand your question.

<select name="variablename">
<option value="value">displayedname
<option value="value2">displayedname2
</select>

That will give you a drop down menu.

Then, with php, depending on "get" or "post" method in your form tag (<form method="get">), you can use:
$_GET['variablename'] or $_POST['variablename'] to use those sent values.

Is this close?

Can you please link to the page you are having trouble with? It's a bit hard to understand what you want.

Twey
05-01-2006, 12:11 PM
<select multiple="true">
<?php
$dbuser = "your user";
$dbpass = "your password";
$dbname = "the name of the database";
$tablename = "the name of the table";
$conn = pg_connect("host=localhost port=5432 dbname=$dbname user=$dbuser pass=$dbpass");
$query = "SELECT * FROM $tablename;";
$rs = pg_query($query, $conn);
while($row = pg_fetch_array($rs)) {
?>
<option value="<?php echo($row['id']); ?>"><?php echo($row['country']); ?></option>
<?php } ?>
</select>