Output to columns php mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
1042
Forum Newbie
Posts: 1
Joined: Sat Feb 17, 2007 5:11 pm

Output to columns php mysql

Post by 1042 »

Hello all,

i have this code that display results in the format

Department A
user1
user2
user3
Department B
user1
user2
user3

below is my code, i have a table called staff departments with the fields dep_id and dep_name and a table for users that holds the staff_departent name;

Code:

Code: Select all

<?
include "inc/staffdirectory.php";
$result = @mysql_query("SELECT DISTINCT dep_name from staff_departments ORDER BY dep_name ASC");
While($row = @mysql_fetch_array($result)) {
echo "<strong>$row[dep_name]</strong><br>"; // Category A, B, etc...
$result2 = @mysql_query("SELECT staff_name, staff_lastname, staff_title, staff_phone from users where staff_office = '$row[dep_name]'");
While($row2 = @mysql_fetch_array($result2)) {
echo "$row2[staff_name]";
echo " ";
echo "$row2[staff_lastname]";
echo " ";
echo "$row2[staff_title]";
echo " ";
echo "$row2[staff_phone]<br>";
} //End Product Loop
} // End Category Loop}
?>
My question is, how can i make it display the results in the format (columns)

Department A | Department B

and the users under each department

thanks for any help in advance.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The first two threads from Useful Posts may be of interest.
Post Reply