0

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);
}
?>

Edited by peck3277: n/a

1
Contributor
2
Replies
3
Views
7 Years
Discussion Span
Last Post by peck3277
0

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!

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.