www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Mysql Query Guidance Needed

  1. #1
    Join Date
    May 2003
    Posts
    599

    resolved [RESOLVED] Mysql Query Guidance Needed

    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.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    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

    eBookworm.us

  3. #3
    Join Date
    May 2003
    Posts
    599

    resolved

    Wow that's it exactly NogDog. Now I have some more studying to do.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles