viddz
07-30-2012, 09:36 PM
I am working on a inventory control system and i want to edit user who assigned to stores. I user can be assigned to one or more stores. Iam using multiple seletc option.My problem here is in edit user page i wanna show user assigned to stores as selected. But when i am going to do that i got this error(Invalid argument supplied for foreach() on line 194 ) only when user is not assigned for all stores.
eg- say there is 3 stores called A, B and C
1.)if iam going to edit user who assigned to all three stores i won't get any error.
2.)If iam going to edit user who assigned to 2 stores I will get above error twice.
3.)If iam going to edit user who assigned to only one store I will get above error only once.
Pls help me to correct this
this is my code
$emp_id = $_GET['emp_id'];
$result1 = mysql_query("Select *
from members
JOIN store_employee on members.emp_id = store_employee.emp_id
JOIN stores on store_employee.store_id = stores.store_id
where members.emp_id=$emp_id")
or die(mysql_error());
$query="SELECT * FROM stores";
$dropdown = "<select name='store_id[]' multiple='multiple' style='height:80px;' size='5' id='store'>";
$result2 = mysql_query ($query);
while($row2 = mysql_fetch_array($result2))
{
$dropdown .= "\r\n<option value='{$row2['store_id']}'";
foreach(mysql_fetch_array($result1) as $row1) //this is line 194
{
if(($row1['store_id'])==($row2['store_id']))
{
$dropdown .=" selected='selected'";
}
}
$dropdown .= ">{$row2['store_name']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
eg- say there is 3 stores called A, B and C
1.)if iam going to edit user who assigned to all three stores i won't get any error.
2.)If iam going to edit user who assigned to 2 stores I will get above error twice.
3.)If iam going to edit user who assigned to only one store I will get above error only once.
Pls help me to correct this
this is my code
$emp_id = $_GET['emp_id'];
$result1 = mysql_query("Select *
from members
JOIN store_employee on members.emp_id = store_employee.emp_id
JOIN stores on store_employee.store_id = stores.store_id
where members.emp_id=$emp_id")
or die(mysql_error());
$query="SELECT * FROM stores";
$dropdown = "<select name='store_id[]' multiple='multiple' style='height:80px;' size='5' id='store'>";
$result2 = mysql_query ($query);
while($row2 = mysql_fetch_array($result2))
{
$dropdown .= "\r\n<option value='{$row2['store_id']}'";
foreach(mysql_fetch_array($result1) as $row1) //this is line 194
{
if(($row1['store_id'])==($row2['store_id']))
{
$dropdown .=" selected='selected'";
}
}
$dropdown .= ">{$row2['store_name']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;