Array and ID
| From: | Steve Fitzgerald | Date: | Thu, 02 Aug 2001 13:50:31 +0000 |
| Subject: | Array and ID | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-10997@lists.php.net to get a copy of this message | ||
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.
Any suggestions?
// create SQL statement
$sql = "SELECT CompanyName,CompanyID FROM company
ORDER BY CompanyName ASC";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$CompanyName = $row["CompanyName"];
if ($curr_CompanyName == $CompanyName) {
$option_block .= "<OPTION name=\"$CompanyID\" value=\"$CompanyName\"
selected>$CompanyName</OPTION>";
} else {
$option_block .= "<OPTION name=\"$CompanyID\"
value=\"$CompanyName\">$CompanyName</OPTION>";
}
}
?>