Jump to content

Recommended Posts

I have this command that basically populates my website with titles for pages based on the information that is placed within "info.txt" I have multiple titles being created so I'd like a way of putting them in order beside alphabetically.

 

My thought was that I could place numbers as the first character in the "info.txt" file and that would allow me to put the titles in an order I find acceptable. Now this causes the issue that I don't want those numbers displayed on my website. So the Echo needs to strip the number.... I'm lost, but my brain thinks it's a good idea.

 

Here's the code I'm working with:

 

		<tr>
		<td id="body">
			<table id="columns" cellspacing="0">
			<tr>
			<td>

				<h2>LSAV Latest Events</h2>
				<p>Select an event from below to view a gallery of images from that event.</p>
				<ul>
				<?php
				$dir = 'latest-events';
				if ($handle = opendir($dir)) {

				    while (false !== ($file = readdir($handle))) {
						if( $file != '.' && $file != '..') {
							$title = file_get_contents( "$dir/$file/info.txt" );
							echo "<li><a href=\"event-viewer.php?event=$file\">$title</a></li>";
						}
				    }
				    closedir($handle);

you could actually do it inline

...
echo "<li><a href=\"event-viewer.php?event=$file\">" . substr($title, 1) . "</a></li>";
...

 

This code worked great in the fact that it did indeed strip the first letter from my text file, however I can't figure out what is determining the order in which these Titles are displayed. I tried put 1-2-3-4 in front of each title string as well as a-b-c-d and neither worked for me.

 

Any suggestions??

You should use a specific separator character that will never exist in the data, such as a |, between the 'fields' in your data. You would then explode each line using that separator character.

 

What happens with the current code once you get more than 9 events saved in the file?

You should use a specific separator character that will never exist in the data, such as a |, between the 'fields' in your data. You would then explode each line using that separator character.

 

What happens with the current code once you get more than 9 events saved in the file?

 

I get what your saying... Perhaps use letters, a-z = 26... I'll never have more than say 10-15 events listed.

 

I guess my issue right now is that I don't understand what method the PHP is using to sort the items I have now, everything is in alphabetical order off of the first letter of the Title (of course ignoring the letter that I put in front of it i.e. a-z...) except for the last two which start with "Z" and "Q" and are listed in that order.

 

None the less I don't want alpha order I really want to determine the order myself.

 

What I have is this, I have a directory with folders, each folder has photos as well as thumbs of each photo as well as a file named "info.txt". Whatever I type in the "info.txt" file is what shows up on the page as the title of the page containing the photos in that directorty. So each "info.txt" file basically has a few words in it with a year and a couple "-". That's all.

 

When I started this thread all I wanted to accomplish was setting the order in which these titles were displayed, I thought I was on the right track but obviously not.

 

Thanks for all of your help thus far, you have given me exactly what I've asked for... Just seems that what I'm asking for isn't the solution....

Well, I fixed my issue this morning... It seems that PHP was using the first capital letter to use for sorting purposes.

 

I am all good to go .

 

Thanks for everyone's help. I'm sure you'll see more from me :)

 

JT

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.