thanks for the input but no dice... it still bombs out every time. Maybe I should include a bit more code and explanation
what I have is a recursive function whose arguments are a criteria and a id to look up.
what this is for is a org chart lookup so that for example a criteria of Manager with a id of 12345 will then display all managers beneath them and all the employs below them in the org chart as well. Kind of a tree like lookup. So here is some of the code and errors that I get
now if I supply a hardcoded sql statement with the WHERE clause being something like .... WHERE Type = 'Manager' and ReportsToID='12345' then everything works like a charm, but when I use variables I get several different errors ranging from parse errors on line ... (the line of the sql statement) to Netscape errors of the dreaded "no data found" or IE errors of "page can not be displayed"
so it sounds like some sort of variable interpolation problem within the WHERE clause of the variable $statement
I have tried all of the following WHERE clauses with no avail
... WHERE Type = {$crit} and ReportsToID = {$id} ";
... WHERE Type = '$crit' and ReportsToID = '$id' ";
... WHERE Type = ' " . $crit ." ' and ReportsToID = ' " . $id} . " ' ";
... WHERE Type = ' \'$crit\' ' and ReportsToID = ' \'$id\' ' ";
... WHERE Type = $crit and ReportsToID = $id ";
... WHERE Type = ' '$crit' ' and ReportsToID = ' '$id' ' ";
Since all of this
function doQuery($criteria, $id){
if ($criteria == "Manager") {
$crit = "Manager";
$statement = "SELECT ID, FirstName, LastName, Type, EmailAddress, ReportsToID, ReportsToName FROM OrgChart WHERE Type = {$crit} and ReportsToID = {$id} ";
}
elseif ($criteria == "Employee") {
$crit = "Employee";
$statement = "SELECT ID, FirstName, LastName, Type, EmailAddress, ReportsToID, ReportsToName FROM OrgChart WHERE Type = {$crit} and ReportsToID = {$id} ";;
}
else{
$msg = "You must specify a search criteria as you searched for $criteria and the userid supplied is $username";
printError($msg);
}
if (!($link=mysql_connect($hostName, $userName, $passWord))){
printError(sprintf("error contecting to host %s, by user %s", $hostName, $userName));
}
// Select the db
if (!mysql_select_db($databaseName, $link)){
printError(sprintf("Error in selecting %s database", $databaseName));
printError(sprintf("Error:%d %s", mysql_errno($link), mysql_error($link)));
}
// Here we are getting the users information by constructing a SQL statement
if (!($result = mysql_query($statement, $link))){
printError(sprintf("Error in executing %s statement", $statement));
printError(sprintf("Error:%d %s", mysql_errno($link), mysql_error($link)));
exit();
}
$num = mysql_num_rows ($result);
// no records found thus a userid was not passed;
if ($num == 0){
// NO RECORDS WERE FOUND SO I NEED TO DISPLAY THE DEFAULTS
// AND EXIT THE FUNCTION
}
else{
while (($row = mysql_fetch_object($result))){
$ID = $row->ID;
$FirstName = $row->FirstName;
$LastName = $row->LastName;
$Type = $row->Type;
$EmailAddress = $row->EmailAddress;
$ReportsToId = $row->ReportsToID;
$ReportsToName = $row->ReportsToName;
echo("<tr>");
echo("<td><a href=\"details.php?id=$ID\">$FirstName $LastName</a></td>");
echo("<td>$Type</td>");
echo("<td><a href=\"mailto:$EmailAddress\">$EmailAddress</a></td>");
echo("<td><a href=\"details.php?id=$ReportsToId\">$ReportsToName</a></td>");
echo("</tr>");
}
}
doQuery("$crit", "$ID");
}
Kudos to those who made it this far, and even more kudos for those with any ideas.