mOrloff
11-20-2010, 04:59 AM
I have a table of employees.
Under normal circumstances I loop through the whole array and gather data for all employees, however, if an employee is specified via $_GET, then I want to limit the scope to that single emp.
Here's a simplified example:
$empArray=array(1=>"Bob",2=>"Sally", 3=>"Dick", 4=>"Harry");
if(empty($_GET['empId'])){ // if NO emp is specified...
foreach($empArray as $empId=>$name){ //...go into a loop
}else{ // if an emp IS specified...
$empID=;$_GET['empId'] //...grab it
}
echo "ID: $empId <br/>";
echo "Name: $name <br/>";
if(empty($_GET['empId'])){ // if NO emp is specified..
} //...close the FOREACH() loop
}
I am getting an error on the }else{ line.
How can this be done??
How can I use the foreach() only if certain criteria are met??
Thanks-a-bunch,
~ Mo
Under normal circumstances I loop through the whole array and gather data for all employees, however, if an employee is specified via $_GET, then I want to limit the scope to that single emp.
Here's a simplified example:
$empArray=array(1=>"Bob",2=>"Sally", 3=>"Dick", 4=>"Harry");
if(empty($_GET['empId'])){ // if NO emp is specified...
foreach($empArray as $empId=>$name){ //...go into a loop
}else{ // if an emp IS specified...
$empID=;$_GET['empId'] //...grab it
}
echo "ID: $empId <br/>";
echo "Name: $name <br/>";
if(empty($_GET['empId'])){ // if NO emp is specified..
} //...close the FOREACH() loop
}
I am getting an error on the }else{ line.
How can this be done??
How can I use the foreach() only if certain criteria are met??
Thanks-a-bunch,
~ Mo