I have a SELECT statement that pulls out a list of titles, URLs and descriptions and sorts alphabetically. Fine.
I want to group those titles, URLs and descriptions in alphabetical groups (titles beginning with A, titles beginning with B......titles beginning with Z).
Then I want to display each one of those groups in various places on the page.
The SELECT statement looks like this:
$qry = "SELECT item.title, item.URL FROM item, alpha WHERE alpha.alpha='A' AND alpha.ID = item.ID ORDER BY item.title";
$results = mysql_query($qry) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
echo "<a href=" . $row['URL'] . ">" . $row['name'] . "</a><br>";
}
I can just sort the titles alphabetically using just the 'item' table OR I can utilize the 'alpha' table (as I do above) to get the same alphabetical list based on title. I thought that using the 'alpha' table might help. It has values A, B, C, D......Z.
The problem comes when I want to put them by alphabetical groups. I could just use the SELECT statement above for each letter (alpha.alpha = 'B', alpha.alpha = 'C', etc), but I would have to do that 26 times. Kind of overkill.
I read a bit about the foreach statement and arrays and am thinking that is how to approach it. However, I am stuck and need some guidance.