Hi,
I do not get any errors, other than the page does not display. This indicates that I have a typo/error in my code syntax.
As far as the condition, the first example works and I have been using this method successfully; i.e.
$query2 = "SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst";
$result2 = mysql_query($query2) or die("Error with query 2.");
$row2 = mysql_fetch_array($result2);
if($row2) {
print "PRINT SELECT BOX";
}
else {
print "ADD RECORD";
}
So I'm pretty sure I've set the condition by assigning it a variable instead of saying:
if (
mysql_fetch_array(
mysql_query(SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst)
)
)
Also, I've added additional comments to code to clarify logic. I start with "if results are found", not "if no results are found." Should I do the opposite?
// this works. i.e. it prints "PRINT SELECT BOX" because records were found
$query2 = "SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst";
$result2 = mysql_query($query2) or die("Error with query 2.");
$row2 = mysql_fetch_array($result2);
if($row2) {
print "PRINT SELECT BOX";
}
else {
print "ADD RECORD";
}
//this also works ... prints dynamic SELECT box & HREF link
$query2 = "SELECT * FROM employeeProfile WHERE CompanyID=$CoID ORDER BY EmployeeLast,EmployeeFirst";
$result2 = mysql_query($query2) or die("Error with query 2.");
print "<FORM ACTION=/"filename.php?id=$id/" METHOD=/"POST/">
<SELECT SIZE=/"1/" name=/"id/">";
while($line = mysql_fetch_array($result2))
{
$lastname = $line["EmployeeLast"];
$firstname = $line["EmployeeFirst"];
$EEid= $line["EmployeeID"];
echo "<OPTION VALUE='$EEid'>$lastname, $firstname</OPTION>";
}
print "</SELECT>
<INPUT TYPE=/"submit/" NAME=/"Print/" VALUE=/"Print/" class=/"small/">";
print "<br>
<A HREF=/"employees_add.php/">Add Employee</A>";
//this doesn't work ... does it have something to do with WHILE statement?
$row2 = mysql_fetch_array($result2);
//if results are found, print dynamic select box
if($row2) {
print "<FORM ACTION=/"filename.php?id=$id/" METHOD=/"POST/">
<SELECT SIZE=/"1/" name=/"id/">";
while($line = mysql_fetch_array($result2))
{
$lastname = $line["EmployeeLast"];
$firstname = $line["EmployeeFirst"];
$EEid= $line["EmployeeID"];
echo "<OPTION VALUE='$EEid'>$lastname, $firstname</OPTION>";
}
print "</SELECT>
<INPUT TYPE=/"submit/" NAME=/"Print/" VALUE=/"Print/" class=/"small/">";
}
//if no results are found, print HREF link
else {
print "<A HREF=/"employees_add.php/">Add Employee</A>";
}