I have looked how to do this everywhere but can't find an answer. Can anybody help?!
I have two mysql tables - store_customer & store_company. Each customer can belong to only one company, and there can be many companies. They are related via a unique company_id. When a customers details are edited in the admin area, I would like their company to be already selected in a drop down list box. If the company they belong to needs to be changed, a different one is selected & when all amendments have been made, a button is clicked and the database is updated. I hope that made sense - I'd appreciate any help.
My form currently updates all the other details. The drop down list box code I have written so far is as follows;
I have two mysql tables - store_customer & store_company. Each customer can belong to only one company, and there can be many companies. They are related via a unique company_id. When a customers details are edited in the admin area, I would like their company to be already selected in a drop down list box. If the company they belong to needs to be changed, a different one is selected & when all amendments have been made, a button is clicked and the database is updated. I hope that made sense - I'd appreciate any help.
My form currently updates all the other details. The drop down list box code I have written so far is as follows;
Code:
print "<select class=\"box\" name=\"company_id\">
<option value=\"all\" ";if($company_id=="all"){echo "selected";}echo">$company_name</option>";
$select = mysql_query("select * from ".$prefix."store_company");
while ($row = mysql_fetch_array($select))
{
$company_id = $row["company_id"];
$company_name = $row["company_name"];
echo"<option value=\"$company_id\" ";
if($list_comp==$company_id){echo "selected";
}echo">";
$company_id = $row["company_id"];
print "$company_name";
echo"</option>";}