Re: Array and ID
| From: | Johannes Janson | Date: | Thu, 02 Aug 2001 15:29:49 +0000 |
| Subject: | Re: Array and ID | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11000@lists.php.net to get a copy of this message | ||
Hi,
> I have a drop-down menu that has been prepopulated with an array from a
> column name CompanyName. What I need to do is take the CompanyName lookup
> the CompanyID in the company table and insert the CompanyID into a row in
a
> table called contacts with a CompnayID column.
[...]
Is this a multiple or a single select?
A quick and dirty thought:
<?php
$sql and $query as they were
echo "<select name=\"company\">";
while ($row = mysql_fetch_array($query)) {
echo "<option
value=\"$row['CompanyID']\">$row['CompanyName']</option>";
// I didn't get the if-else statement you had here before. I think it is
better to have
// the id as the value and not the name.
}
?>
So if the from (which I assume you are using) is submitted you have $company
with
the CompanyID as its value which then can be inserted. If it is a multiple
select you
have to do it with an array but shouldn't be too tricky either
hope it helps
Johannes