Here is my problem. I would like to know how to sort a flat text file database before I run it through the following. As long as the text file is in alphabetical order according to the first letter then this works but that is not possible since links are not added in order.
I am at a loss. any help or direction would be appreciated.
<?
//initialize
$old_letter = '';
//read file and get count of lines
$file = file("$datafile");
$count = count($file);
//loop through lines
for($x=0;$x<$count;$x++)
{
//explode each line on ||
$line = explode("||",$file[$x]);
//capture first letter of $line[0] and
//convert it to uppercase
$letter = strtoupper(substr($line[0],0,1));
//if the letter has changed, print it out
//this makes your "letter" headings/categories
if($letter != $old_letter)
{
echo "<TR><TD COLSPAN='5' ALIGN=CENTER valign=bottom HEIGHT=100><FONT SIZE=+3>$letter</font></TD></TR>";
$old_letter = $letter;
}
//echo out rest of information in line
//you'll add your table info and all of that in here...
echo "<tr><td>$line[0] -- $line[1] -- $line[2] -- $line[3] -- $line[4] -- $line[5]-- $line[6] -- $line[7] -- $line[8] -- $line[9] -- $line[10] -- $line[11] -- $line[12] -- $line[13]</tr></td>";
}
?>
-----------------------Output
A
Alpha Site -- One -- Two -- Three
B
Beta Site -- 1 -- 2 -- 3
Barnyard Site -- Red -- Blue -- Green
Bunny Site -- White -- Red -- Blue
C
Charlie Site -- 13 -- 11 -- 24
Crappy Site -- No -- Yes -- Maybe
thanks jobesd