Forum Moderators: coopster
(I'm pulling the data from a MySQL database before making an array.)
Any Ideas?
I've looked around the pages on php.net on array_diff, array_filter, array_unique and array_merge, but I'm not seeing a direction that looks promising.
If no listings exist for a certain letter, it should be shown, but should not be a link.
This infers you're connecting with the database and running a query on the data for every.single.navigation, is this correct?
I'd approach this a little differently. You have some function that inserts/adds/modifies/deletes records. Whatever that function is, and wherever it occurs, you would also update a small table, 26 records deep, A-Z.
letter ¦ records
A ¦ 3
B ¦ 24
C ¦ 0
........
So you'd just query this small table rather than searching/counting your records.
Alternatively, this "dataset" is so small you could store it in a text file and include it.
So,
foreach ($letter as $key=>$value) {
$nav .= ($value>0)?" <a href=\"$link?L=$key\">$key</a> ¦ ":" $key ¦ ";
}
You'd have to add an if or do something to lose the last pipe, but those are the cliff notes . . .