Hello,
I am having trouble with a select query. I hope you can assist.
Goal: Query one database for all employees that have registered for a particular event.
$query_Recordset1 = "SELECT employee_id FROM signup WHERE event = '2004_lightning'";
$Recordset1 = mysql_query($query_Recordset1, $signup) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
I then need to take the results from the first query and query a different database containing all employees and display only the employees that did not register for the event. (entire employee list minus the results from the first query).
Each database table has an employee_id column that can be used to relate records.
I figured I could take the results from the first query and make them into an array (I don't know how to do this) and use that array in the select statement for the second query (I'm not sure how to do this either).
$query_Recordset2 = "SELECT * FROM employees WHERE employee_id != $array???";
Can anyone help?Well, I got something to work. I'm not sure if it was the best way to do it, but it's working...
mysql_select_db($database_surveyColumbus, $surveyColumbus);
$result = mysql_query("SELECT employee_id FROM signup WHERE event = 'champs_lightning' ORDER by employee_id ASC");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)){
$array[$c] = $row["employee_id"];
$c = $c+1;
}
$comma_separated = implode(",", $array);
mysql_select_db($database_employeeList, $employeeList);
$query_Recordset2 = "SELECT ID, LastName, FirstName, Status FROM employees WHERE ID not in (%s) and status = 'active'";
$query_Recordset2 = sprintf($query_Recordset2, $comma_separated);
$Recordset2 = mysql_query($query_Recordset2, $employeeList) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);might possibily do it this way too
mysql_select_db($database_surveyColumbus, $surveyColumbus);
$result = mysql_query("SELECT employee_id FROM signup WHERE event = 'champs_lightning' ORDER by employee_id ASC");
while ($row = mysql_fetch_array($result)){
$array[] = $row["employee_id"];
}
$comma_separated = implode(",", $array);
$query_Recordset2 = "SELECT ID, LastName, FirstName, Status FROM employees WHERE ID not in ($comma_separated) and status = 'active'";
$Recordset2 = mysql_query($query_Recordset2, $employeeList) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);Thanks Scoutt... Your code worked great
I am having trouble with a select query. I hope you can assist.
Goal: Query one database for all employees that have registered for a particular event.
$query_Recordset1 = "SELECT employee_id FROM signup WHERE event = '2004_lightning'";
$Recordset1 = mysql_query($query_Recordset1, $signup) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
I then need to take the results from the first query and query a different database containing all employees and display only the employees that did not register for the event. (entire employee list minus the results from the first query).
Each database table has an employee_id column that can be used to relate records.
I figured I could take the results from the first query and make them into an array (I don't know how to do this) and use that array in the select statement for the second query (I'm not sure how to do this either).
$query_Recordset2 = "SELECT * FROM employees WHERE employee_id != $array???";
Can anyone help?Well, I got something to work. I'm not sure if it was the best way to do it, but it's working...
mysql_select_db($database_surveyColumbus, $surveyColumbus);
$result = mysql_query("SELECT employee_id FROM signup WHERE event = 'champs_lightning' ORDER by employee_id ASC");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)){
$array[$c] = $row["employee_id"];
$c = $c+1;
}
$comma_separated = implode(",", $array);
mysql_select_db($database_employeeList, $employeeList);
$query_Recordset2 = "SELECT ID, LastName, FirstName, Status FROM employees WHERE ID not in (%s) and status = 'active'";
$query_Recordset2 = sprintf($query_Recordset2, $comma_separated);
$Recordset2 = mysql_query($query_Recordset2, $employeeList) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);might possibily do it this way too
mysql_select_db($database_surveyColumbus, $surveyColumbus);
$result = mysql_query("SELECT employee_id FROM signup WHERE event = 'champs_lightning' ORDER by employee_id ASC");
while ($row = mysql_fetch_array($result)){
$array[] = $row["employee_id"];
}
$comma_separated = implode(",", $array);
$query_Recordset2 = "SELECT ID, LastName, FirstName, Status FROM employees WHERE ID not in ($comma_separated) and status = 'active'";
$Recordset2 = mysql_query($query_Recordset2, $employeeList) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);Thanks Scoutt... Your code worked great