SELECT dropdown from a db query?
| From: | Andre Dubuc | Date: | Thu, 19 Sep 2002 01:34:20 +0000 |
| Subject: | SELECT dropdown from a db query? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116821@lists.php.net to get a copy of this message | ||
I'm trying to generate a dropdown SELECT list from a database query. So far,
all I've managed to create is multiple one-item dropdowns for each database
entry spread across the page. Bad -- very bad!
I'd like normal drop-down SELECT behavior, but somehow the code escapes me.
I've tried a bunch of permutations, but I either end up with an empty
dropdown or multiple single entry messes.
Is there anyway to iterate through this and achieve what I want?
I would greatly appreciate any hints what I'm missing here or doing wrong.
Code follows.
Tia,
Andre
Code (using PostgreSQL):
<?php
. . .
$query = "SELECT * FROM rap WHERE rsponsor = '{$_SESSION['sid']}'";
$result = pg_exec($db, $query);
if (!$result) {exit;}
$numrows = pg_numrows($result);
if ($numrows == 0) {echo
"<h2>Sorry!<br><br>'{$_POST['sid']}' is not in the
our database.<br><br> Click 'Back' on
your browser to enter another search.<br><br></h2>"; exit;}
$row = 0;
do
{
$myrow = pg_fetch_array($result,$row);
if ($myrow['rupload'] != "")
{
print "<SELECT name=rapped><option>{$myrow['rfname']}
{$myrow['rsname']}</select>";
}
$row++;
}
while ($row < $numrows);
pg_close($db);
?>