I don't work much with mysql, and need input on how to structure a query (or series of query's).
I am working with a task-assignment application, and the table I am trying to query contains records of: employee_num, employee_name, task_assigned, project_num.
The report I am trying to form is based on project_num, & I want to find all employee_names assigned to each task
Example: Project_num: AA-345 Assigned to task 1: Joe Smith, Frank Furter Assigned to task 2: Chili Cheesefries, John Doe, Ham Hock
I am stuck on how to structure this report. it seems like it should be easy though, I just need to find out who is assigned to what under each project.
You could do something like this (require MySQL 4.1 or later):
PHP Code:
$sql = "
SELECT `task_assigned`, GROUP_CONCAT(`employee_name` SEPARATOR ', ') AS emp_list
FROM `task_assignment`
WHERE `project_num` = '$projectNum'
GROUP BY `task_assigned`
";
$result = myql_query($sql) or die("Query failed ($sql): " . mysql_error());
echo "<h2>Project: $projectNum</h2>\n";
echo "<ul>\n";
while($row = mysql_fetch_assoc($result))
{
printf(
"<li><strong>Assigned to Task %s:</strong><br />%s</li>\n",
$row['task_assigned'],
$row['emp_list']
);
}
echo "</ul>\n";
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks