displaying query results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a query that returns a list of staff members and which department
they are in. There's one table for departments, which is joined to the table
for staff members. Using the typical methods, I am currently displaying the
results in the form of Deparment Name: Staff Name for each staff member.
What I would like to do, however, is have the department name only appear
once, and then have all the staff members from that department listed below
it. Like:

Accounting
John Smith
Frank Jones
Sara Banks

Clerical
Fred Smith
John Simple

Current Code is below:

$sql = "SELECT job_cat_name, staff_fname, staff_lname, staff_desc FROM
job_cat, emp_directory2
  WHERE job_cat.job_cat_id = emp_directory2.job_cat_id ORDER BY
job_cat_name, staff_lname";

  $result = @mysql_query($sql,$connection) or die ("problem with job_cat SQL
query");
   echo "<table>";
  while ($row = mysql_fetch_array($result)) {
  $job_cat_name = $row['job_cat_name'];
  $staff_fname = $row['staff_fname'];
  $staff_lname = $row['staff_lname'];
  $staff_desc = $row['staff_desc'];

  echo "<tr>";
  for ($i = 0; $i < count($num); $i++) {

  echo "<td width='20%' class='$bg'><b>$job_cat_name</b></td><td width='40%'
class='$bg'>$staff_fname $staff_lname</td><td width='40%'
class='$bg'>$staff_desc</span></td>";

  }
  } //close while loop
  echo "</tr></table>";

Thanks,

Sam



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux