Hi,
Could anybody help me with a telephone directory I am trying to create?
I have a database with various members, each belonging to a department. I need to sort the list by department, giving the title of the department in a line of the table, followed by the members of the department each as lines of the table. I'm using PHP amd MySql.
When there are no more members in a department, I need to then move onto the next department, and list the staff there, and so on until all departments and staff have been listed.
Here's a piece of code that lists all of the staff in the directory:
while($myrow = mysql_fetch_array($result)){
$newID = $myrow['0'];
$newFirstName = $myrow['1'];
$newSurname = $myrow['2'];
$newState = $myrow['3'];
$newTelephone = $myrow['4'];
$newDirectLine = $myrow['5'];
$newMobile = $myrow['6'];
$newFax = $myrow['7'];
$newEmail = $myrow['8'];
$newDepartment = $myrow['9'];
$newJobTitle = $myrow['10'];
$newCarReg = $myrow['11'];
$newPicture = $myrow['12'];
$newLocation = $myrow['13'];
$newImportance = $myrow['14'];
$displayblock3 .= "
<tr><td valign='top'>
<p class='DarkFont'><a href='mailto:$newEmail' class='DarkFontSmall'>$newFirstName $newSurname</a></td>
<td valign='top'><p class='DarkFontSmall'>$newJobTitle</p></td>
<td valign='top'><p class='DarkFontSmall'>$newDirectLine</p></td>
<td valign='top'><p class='DarkFontSmall'>$newTelephone</p></td>
<td valign='top'><p class='DarkFontSmall'>$newFax</p></td>
<td valign='top'><p class='DarkFontSmall'>$newMobile</p></td>
</tr><tr><td colspan='6'><img src='images/spacer-black.gif' width='100%' height='1'></td></tr>
";
}
And here is a piece of code that lists all of the departments available:
while($myrow2 = mysql_fetch_array($result2)){
$newDept = $myrow2['0'];
print"<table border='0' width='650' align='center' cellpadding='2' cellspacing='0' bgcolor='#FFFFFF' class='border-black'>\n";
print"<tr bgcolor='#90A7D6'>\n";
print"<td colspan='6'><p class='whitefont'><b>$newDept</b></p></td>\n";
print"</tr>\n";
Can anybody tell me how I make a loop to do this or point me in the right direction?
All ideas appreciated...
Thanks
Caz