A | B | C | D | E... etc
Then beneath the anchor links I want to display the letter header with its results in two columns, such as:
A
Adams, Bob Anderson, Mark
Allen, Tom Anthony, Craig
B
Black, Jack Booth, Nick
Boone, Ed Bronson, Fred
I've tried to put all of the pieces together and I've gotten most of it completed, except for breaking the results down to two columns. So far, here is what I've got:
Code: Select all
$result2 = mysql_query("SELECT DISTINCT SUBSTRING(last_name, 1, 1) AS letter FROM members ORDER BY letter");
$num_rows = mysql_num_rows($result2);
$i = 0;
while ($row = mysql_fetch_assoc($result2)) {
$letter_link = $row['letter'];
$i++;
if ($i == $num_rows) {
echo "<a href='#$letter_link'>$letter_link</a>"; }
else { echo "<a href='#$letter_link'>$letter_link</a> | "; }
}
echo "<br><br>";
$result = mysql_query("SELECT * FROM members ORDER BY last_name ASC");
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$first_name = $row['first_name'];
$middle_name = $row['middle_name'];
$last_name = $row['last_name'];
$array_letter = substr($row['last_name'], 0, 1);
if($array_letter != $letter) {
$letter = $array_letter;
echo "<br><a name='". $letter ."'></a><b>". $letter ."</b><br><img src='images/divider.jpg' width='500' height='21'><br>"; }
echo "<a href='attorneys.php?action=view&id=$id'>$last_name, $first_name"; if (!empty($middle_name)) { echo " $middle_name"; } else { echo ""; } echo "</a><br>";
}
This does everything I want it to do, except break the results down into 2 columns. If someone could aid me how to edit the above code to allow for a 2 column result and also I will probably be looking to setup the 2 columns to display a different result set. For example, the first column would have a subheader of Partners and the 2nd column would have a subheading of Associates. I would get these results from a "position" column that is in the database.
Any help would be much appreciated!