...

View Full Version : Group results aplhabetically



gadaschowdary
10-09-2009, 08:12 PM
Hello

I am getting the files from a directory, by using the code below.
Now i want to have A B C D ...Z as hyperlinks and when we click on a particular letter it should show files starting with that letter only.
Any help pleaze.....

<?
$file_available = "FALSE";
if ($handle = opendir('voicefiles')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." )
{
$file_available = "TRUE";
break;
}
}
closedir($handle);
}

if($file_available != 'FALSE')
{
?>

<?php
if ($handle = opendir('voicefiles')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." )
{
$number = $file;
$chkbox = "chkbox$number";
$thelist = '<a href="voicefiles/'.$file.'">'.$file.'</a><br>';?>
<?echo $thelist;
}
}
closedir($handle);
}
?>

<P><? //echo $thelist?></p>


<?
}
else
{
echo "No Prompt files found";
}
?>

oesxyl
10-09-2009, 08:30 PM
use scandir

http://www.php.net/manual/en/function.scandir.php

or put filename in a array and sort alphabeticaly when you finish.

best regards

mlseim
10-09-2009, 08:36 PM
<?php
// Not sure how you're doing your A,B,C links, but from a URL link ...
// like this, <a href="search.php?letter=B">B</a> ...

// Get the letter to search for, from the URL.
$l=strtolower($_GET['letter']);

$file_available = "FALSE";
if ($handle = opendir('voicefiles')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." )
{
$file_available = "TRUE";
break;
}
}
closedir($handle);
}

if($file_available != 'FALSE')
{
?>

<?php
if ($handle = opendir('voicefiles')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." )
{
$testfile=strtolower($file);
// Look at the first character of the lower-case filename.
if (substr($testfile, 0 ,1) == $l){
$number = $file;
$chkbox = "chkbox$number";
$thelist = '<a href="voicefiles/'.$file.'">'.$file.'</a><br>';?>
<?echo $thelist;
}
}
}
closedir($handle);
}
?>

<P><? //echo $thelist?></p>


<?
}
else
{
echo "No Prompt files found";
}
?>

gadaschowdary
10-12-2009, 05:57 PM
hey thank you so much it worked like a charm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum