Hey guys, seriously going mad here, any help is appreciated.

I have a directory of .txt files. What I want is this.

I want to go through this directory and display it like something like this:

A
All files beginning with A

B
All files beginning with B

etc.

The letters will be in one div and the files in a seperate div.

This is what I have, bear with me, it's probably going in the wrong direction. Thanks to any and all contributions!

<?php
	if ($handle = opendir('poems/')) {
    while (false !== ($file = readdir($handle))) {
		for ($i=65; $i<=90; $i++){
			$n=chr($i);
			echo '<div class="list">';
			echo '<div class="large">';
                        echo chr($i);
			echo '</div>';
        if ($file != "." && $file != ".." && $file[0] == $n) {
			echo '<div class="small"><div class="list2">';
			echo "<a href=\"poems/$file\" class='nav'>$file</a><br />";
			echo '</div>';
			echo '</div>';
        }
		}
		
    }
closedir($handle);
}
?>

What I'm trying to acheive is generating the following html.

<div class="list">
			<div class="large">V</div>
			<div class="small"><div class="list2">
			<a href="#" class="nav">test</a><br />
			<a href="#" class="nav">test</a>
			</div>
			</div>
		</div>

I want it to be populate automatically instead of entering it for each and every letter. Thanks!

Never mind I finally figured it out for myself!!

If anyone is interested this is what I eneded up using!

<?php
	echo '<div class="list">';
	for ($j=65; $j<=90; $j++){
		$a=chr($j);
		if ($a != "J" && $a != "Q" && $a != "X" && $a != "Z") {
		echo '<div class="large">'.$a.'</div>';
		}
		if ($handle = opendir('poems/')) {
			while (false !== ($file = readdir($handle))) {
				if ($file != "." && $file != ".." && $file[0] == $a) {
					echo '<div class="small"><div class="list2">';
					echo "<a href=\"poems/$file\" class='nav'>$file</a><br />";
					echo '</div>';
					echo '</div>';
					}
				}
			}
		closedir($handle);
		}
?>

Only took me 3-4 hours :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.