Schlo_50 Posted December 17, 2007 Share Posted December 17, 2007 Hey guys, I have some categories ($catname) and need to order them alphabetically a-z. Any ideas? Anyone? $imagename = trim($Data[$i][0]); $catname = trim($Data[$i][1]); if(strlen($catname) > 12){ $catname = substr($catname, 0, 12); $catname = trim($catname); $catname = "$catname..."; } else { $catname = $catname; } $description = str_replace("[break]", "<br>", $Data[$i][2]); $data = file("admin/data/threads.DAT"); $Lines = find_by_col($data, 3, $imagename); $itemcount = count($Lines); if(file_exists("$imgdir/$imagename.jpg")){ $img = "$imgdir/$imagename.jpg"; } else { $img = "$noimgdir/comingsoon.jpg"; } if (($i % 3) === 0 && $i > 0) { print "</tr><tr>\n"; } print "<td><p align=\"center\"><a href=\"$link=$imagename\"><img src=\"$img\" border=\"0\"><br><b>$catname</b></a><br>$description</p></td>\n"; } print "</tr>"; print "</table>"; Thanks Link to comment https://forums.phpfreaks.com/topic/82022-ordering-categories-into-alphabetical-order/ Share on other sites More sharing options...
paul2463 Posted December 17, 2007 Share Posted December 17, 2007 i found this in a search, not sure it is what you want but you may be able to modify to do what you wish <?php if ($handle = opendir('.')) { // read the current directory. Change the "." to the directory you need. $filecount = "0"; //reset the number of files while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { // remove the move up directory commands. (. and ..) $file = strtolower($file); // make all filenames lowercase (looks better. can be removed) $fileList[] = trim($file); // add the file to an array so it can be sorted easily. $filecount = $filecount + 1; //count the number of files } } print 'File Count: <b>'.$filecount.'</b><br>'; //display the number of files sort ($fileList); // sort the file list in the array reset ($fileList); // go back to the top of the array while (list ($key, $val) = each ($fileList)) { echo $val.'<br>'; //print the list. } closedir($handle); } ?> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/82022-ordering-categories-into-alphabetical-order/#findComment-416816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.