Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

Alphabetically ordering url's list


(!)

howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
17-Jul-2012, 08:40 AM #1
Alphabetically ordering url's list
Hi all.

I am in the process of creating a web site, part of which involves working with some quite long lists of url's.

Here is list of 7 example url's which I have composed for the purpose of this post.

<a href="http://www.mydomain.com/healthy-eating/less-chocolate?5266" title="Eat Less Chocolate">Eat Less chocolate</a>
<a href="http://www.mydomain.com/fun-stuff/paint_and_draw?5266" title="Learn to Draw and Paint">Learn to Draw and Paint</a>
<a href="http://www.mydomain.com/sports_activities/swimming-skills?5266" title="Improve Your Swimming Abilities">Improve Your Swimming Abilities</a>
<a href="http://www.mydomain.com/healthy-eating/veg-more?5266" title="Enjoy More Vegetables">Enjoy More Vegetables</a>
<a href="http://www.mydomain.com/addiction_help/smoking-cessation?5266" title="Quit Smoking Tips">Quit Smoking Tips</a>
<a href="http://www.mydomain.com/automobile/cleaner_car?5266" title="Clean Car">Clean Car</a>
<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>
<a href="http://www.mydomain.com/healthy-eating/make_yogurt?5266" title="Yogurt Making Guide">Yogurt Making Guide</a>

In reality I have a list of perhaps 800 similar url's which I would like to sort into alphabetical order by means of title tag, or
by means of the visible page link.

I realise that I can sort all my lists manually, a task which will probably take me many, many hours for each, but if there is an easier and less time consuming way then it couldn't hurt to use it.

To this end, I have tried playing around with an online program called Alphabetizer by Flap TV, and a few other similar variations,but no matter what I do, the software always sorts each individual url by means of the first unique letter it encounters - meaning that it will order the above list like so:

<a href="http://www.mydomain.com/addiction_help/smoking-cessation?5266" title="Quit Smoking Tips">Quit Smoking Tips</a>
<a href="http://www.mydomain.com/automobile/cleaner_car?5266" title="Clean Car">Clean Car</a>
<a href="http://www.mydomain.com/fun-stuff/paint_and_draw?5266" title="Learn to Draw and Paint">Learn to Draw and Paint</a>
<a href="http://www.mydomain.com/healthy-eating/less-chocolate?5266" title="Eat Less Chocolate">Eat Less chocolate</a>
<a href="http://www.mydomain.com/healthy-eating/make_yogurt?5266" title="Yogurt Making Guide">Yogurt Making Guide</a>
<a href="http://www.mydomain.com/healthy-eating/veg-more?5266" title="Enjoy More Vegetables">Enjoy More Vegetables</a>
<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>
<a href="http://www.mydomain.com/sports_activities/swimming-skills?5266" title="Improve Your Swimming Abilities">Improve Your Swimming Abilities</a>

As you can see, the Alphabetizer has ordered my list by catagory, or by means of the first letter of the word which directly follows: <a href="http://www.mydomain.com/

Taking the following as an example:

<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>

Is there any way that I can get automatic software to order my list by means of the last part of the url which contains, for instance:

title="Get More Exercise">Get More Exercise</a>

whilst ignoring (leaving attached and intact) the first part, for instance:

<a href="http://www.mydomain.com/personal-health/exercise_easily?5266"

so that I end up with a list which looks like this:

<a href="http://www.mydomain.com/automobile/cleaner_car?5266" title="Clean Car">Clean Car</a>
<a href="http://www.mydomain.com/healthy-eating/less-chocolate?5266" title="Eat Less Chocolate">Eat Less chocolate</a>
<a href="http://www.mydomain.com/healthy-eating/veg-more?5266" title="Enjoy More Vegetables">Enjoy More Vegetables</a>
<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>
<a href="http://www.mydomain.com/sports_activities/swimming-skills?5266" title="Improve Your Swimming Abilities">Improve Your Swimming Abilities</a>
<a href="http://www.mydomain.com/fun-stuff/paint_and_draw?5266" title="Learn to Draw and Paint">Learn to Draw and Paint</a>
<a href="http://www.mydomain.com/addiction_help/smoking-cessation?5266" title="Quit Smoking Tips">Quit Smoking Tips</a>
<a href="http://www.mydomain.com/healthy-eating/make_yogurt?5266" title="Yogurt Making Guide">Yogurt Making Guide</a>

If anyone knows of software, or any other quicker way for me to achieve the desired results, I'd be very grateful if you'd let me know.

Any constructive advice would be very gratefully received.
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 611 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
17-Jul-2012, 01:35 PM #2
Evening Howard,

How are you storing these URL's at the moment? Are they in a database, files on a server or just a list in the HTML?

Danny
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
17-Jul-2012, 02:54 PM #3
Hi Danny and thanks for the answer.

The URL's are just in the form of a list in html. I tend to create most of my web pages using Topstyle Pro. I have been continuing my search this evening, looking for any way to alphabetically sort my url lists, but am still unable to find any automatic way that will alphabetize the title tags, or visible page links, whilst ignoring the rest of the html in each url. Of course, I could remove all of the html from each string up to the title tag, but then marrying up the correct segments after automatically sorting the list (always supposing this could be achieved) would probably be a bigger task than ordering the whole list myself by hand.

It seems strange that no one has ever created software that will achieve the results I am looking for. What I mean to say is that there seems to be software available (either free or paid) that will achieve just about anything you can think of when it comes to music/video/broadcast editing, so I think I must have found a niche not yet exploited!

I would have thought that by automatically adding a unique identifier, such as perhaps a $ symbol, using a program such as simple search/replace, at the beginning and end of the section of each url that I need sorting, that this could act as a marker for some form of software sorting tool to know which part to look at and alphabetize, whilst leaving the rest of the url intact and unaltered. This unique identifier could then be removed again after the list is alphabetized.

Only wish I had the technical knowledge to write a program that would do just this!
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,291 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
17-Jul-2012, 03:10 PM #4
Is it only a single list with all those links, or will it be a repeated task?
If you can send me the whole list, I could sort them for you in no time at all. Making and testing a repeatable script would take a while longer.
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
17-Jul-2012, 03:16 PM #5
There are actually just 2 lists, each containing perhaps between 600 and 1000 links. Both of theses lists will be ready for sorting sometime over the next few days and once I have made final checks to ensure they contain all the necessary links, and that there are no errors.
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 611 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
17-Jul-2012, 03:30 PM #6
There are many, many solutions out there for doing exactly what you are after, but unfortunately they are all server side (or have some form of server side dependance, i.e. database or flat file). For example, if your links were held in a DB on the server, in a table called links with a field called title, you could order your links with one line of code:
Code:
SELECT * FROM links ORDER BY 'title'
This would give you an array of links alphabetically ordered by title tag... You could do it client side (i.e. Javascript), but ideally you'd need to read the data into the page from an external source. It could feasibly be done by ordering the links on the page at run time, but it would be slow, costly (in terms of dev time) and ultimately pointless in the light of other, simpler and quicker options.

If you plan to upkeep this site for any period of time I'd strongly suggest looking into a database storage strategy. It'd be way easier to update you list, and the options available to server side languages such as PHP / MySQL would make ordering and filtering these links so much easier in the long term. Just take a look at the main forum pages, all those links are pulled from a database, they can be automatically updated when new posts come in, and can be ordered, searched and filtered in multiple ways. That's the power of server side scripting...

Danny
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 611 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
17-Jul-2012, 03:32 PM #7
Quote:
Originally Posted by Ent View Post
If you can send me the whole list, I could sort them for you in no time at all.
I'll look after the boards while you're away... See you in a fortnight

Danny
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,291 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
17-Jul-2012, 03:51 PM #8
Quote:
Originally Posted by allnodcoms View Post
I'll look after the boards while you're away... See you in a fortnight

Danny
A fortnight? I was thinking of scripting it too you know; it's just that my favourite language is (compiled) VB.net which isn't suitable for posting on the forums. Besides which, a rapidly written script would use some messy techniques I won't be very proud of in a year or two.

For the record, I agree that in terms of long run maintenance it would be far better to use some sort of database and a touch of PHP.

Last edited by Ent; 17-Jul-2012 at 04:07 PM..
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,291 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
17-Jul-2012, 05:10 PM #9
This may serve your purposes. It's built around a web page itself, so save it in a .htm file and open it in IE, Firefox, or your favourite browser. Essentially you just have to paste the list into the text box and click the Sort Button. The output should replace "No list sorted" in plain text below that.

HTML Code:
<html>
<head>
    <script type="text/javascript">
        function SortData() {
            var unSortedText = document.forms&#91;"SortForm"&#93;&#91;"SortList"&#93;.value
            var SortedText = ""
            var lines = unSortedText.split("\n");
            var numLines = lines.length;
            
            var swapLine = "";
            
            for (R = numLines - 1; R > 0; R-- ) {
                for (l=0; l < R; l++) {
                    if ( lines&#91;l&#93;.slice(lines&#91;l&#93;.indexOf("title=") + 7) > lines&#91;l + 1&#93;.slice(lines&#91;l + 1&#93;.indexOf("title=") + 7) ) 
                        {
                            swapLine = lines&#91;l&#93;;
                            lines&#91;l&#93; = lines&#91;l+1&#93;;
                            lines&#91;l+1&#93; = swapLine;
                        }
                }
            }
        
            for (l=0; l<numLines;l++) {
                lines&#91;l&#93; = lines&#91;l&#93;.replace("<","<");
                lines&#91;l&#93; = lines&#91;l&#93;.replace(">",">");
            }
            
            for (l=0; l<numLines;l++) {
                SortedText = SortedText + lines&#91;l&#93; + "</a> \n<br />";
            }
            
            document.getElementById("Sorted").innerHTML = SortedText;
        }
    </script>
</head>
<body>
    <form name="SortForm" id="SortForm">
        <textarea id="SortList" name="SortList" rows="30" cols="80"> </textarea>
        <input type="button" value="Sort" onclick="SortData()">
    </form>
    <div id="Sorted">No List Sorted</div>
</body>
</html>
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
18-Jul-2012, 05:21 AM #10
Apologies for my delay in replying to your posts. I went offline at about 9.30pm yesterday evening and have only just managed to revisit the thread I began earlier in the day.

Thanks to all who have contributed so far. I am extremely grateful for your time, help and advice.

I am inclined to agree that the best long term solution would probably be with a server side database, except for the fact that my brain seems totally incapable of understanding the likes of MYSQL, Java, Perl, Ajax, Python, and others, the names of which currently escape me. So creating some form of working system along these lines without expert help seems pretty-much out of the question.

I have taught myself how to build web pages from scratch using html, xhtml, css, which for me has been quite an achievement, but how you guys manage to understand some of the other forms of coding mentioned above is nothing short of miraculous. All I can say is that you must be truly gifted!

I am going to have a tinker with the method suggested in the most recent reply and see if it achieves the desired result. Once I have given it a try, I'll post back to let you know how I got on.

Once again, thank you all for your help so far.
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
18-Jul-2012, 06:14 AM #11
Hallelujah, it works!!

I copied and pasted the supplied code into a notepad doc and then saved this as an html doc. I then proceeded to open the page in Firefox and entered my first list into the text area. The entered list isn't yet completely checked for errors, but hey, I thought, let's give it a go anyway . I hit the sort button and held my breath........and.........the resulting list appeared sorted into alphabetical order! Amazing. It's truly staggering what some of you geniuses can achieve with just a few lines of coding. Nevertheless, how on earth you learn all about this stuff and properly understand it is beyond me. Honestly, simply compiling web pages from scratch can have my head round in circles, so I cannot begin to imagine how you cope. Still, I have to admit that the results you have achieved with apparently such a small amount of code does rather intrigue me. Please can you tell me what type of code you have used to create this piece of wizardry, and I shall then take some time to read about, and perhaps attempt to try to understand its basics.

Very many thanks to all who have contributed and should I hit upon any glitches, which I doubt, I'll post back over the coming days.
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
18-Jul-2012, 10:12 AM #12
Okay, so I said I'd post back should I encounter any slight glitches, and after getting over the initial shock of my list appearing sorted upon the click of a button, I then realised that whilst the sorted list appears in perfect alphabetical order, it does not visibly incorporate its associated html. What I mean is, if I paste in the following:

<a href="http://www.mydomain.com/healthy-eating/less-chocolate?5266" title="Eat Less Chocolate">Eat Less chocolate</a>
<a href="http://www.mydomain.com/fun-stuff/paint_and_draw?5266" title="Learn to Draw and Paint">Learn to Draw and Paint</a>
<a href="http://www.mydomain.com/sports_activities/swimming-skills?5266" title="Improve Your Swimming Abilities">Improve Your Swimming Abilities</a>
<a href="http://www.mydomain.com/healthy-eating/veg-more?5266" title="Enjoy More Vegetables">Enjoy More Vegetables</a>
<a href="http://www.mydomain.com/addiction_help/smoking-cessation?5266" title="Quit Smoking Tips">Quit Smoking Tips</a>
<a href="http://www.mydomain.com/automobile/cleaner_car?5266" title="Clean Car">Clean Car</a>
<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>
<a href="http://www.mydomain.com/healthy-eating/make_yogurt?5266" title="Yogurt Making Guide">Yogurt Making Guide</a>

what I get out is:

Clean Car
Eat less Chocolate
Enjoy More Vegetables
Get More Exercise
Improve Your Swimming Abilities
Learn To Draw And Paint
Quit Smoking Tips
Yogurt Making Guide

and not:

<a href="http://www.mydomain.com/automobile/cleaner_car?5266" title="Clean Car">Clean Car</a>
<a href="http://www.mydomain.com/healthy-eating/less-chocolate?5266" title="Eat Less Chocolate">Eat Less chocolate</a>
<a href="http://www.mydomain.com/healthy-eating/veg-more?5266" title="Enjoy More Vegetables">Enjoy More Vegetables</a>
<a href="http://www.mydomain.com/personal-health/exercise_easily?5266" title="Get More Exercise">Get More Exercise</a>
<a href="http://www.mydomain.com/sports_activities/swimming-skills?5266" title="Improve Your Swimming Abilities">Improve Your Swimming Abilities</a>
<a href="http://www.mydomain.com/fun-stuff/paint_and_draw?5266" title="Learn to Draw and Paint">Learn to Draw and Paint</a>
<a href="http://www.mydomain.com/addiction_help/smoking-cessation?5266" title="Quit Smoking Tips">Quit Smoking Tips</a>
<a href="http://www.mydomain.com/healthy-eating/make_yogurt?5266" title="Yogurt Making Guide">Yogurt Making Guide</a>

Okay, no problem, I thought. I can pick up the whole list as one entire block of html, including each complete url, by viewing the page source code, but when I view the source code for the page all I can see is the source for the Javascript tool, with the rest of the page appearing empty.

Obviously, if I click on each of the individual sorted links, I can take its url from the address bar at the top of the page, but this means re-compiling the entire list one at a time.

Is there any chance that the javascript can be tweeked slightly so that the sorted output retains the entire line of code?
howard.a.s's Avatar
howard.a.s howard.a.s is offline
Member with 326 posts.
THREAD STARTER
 
Join Date: Jul 2005
Location: U.K
Experience: Intermediate
18-Jul-2012, 12:25 PM #13
Whoa! Think I may have found the answer myself. After some head scratching and googling I came upon this page:

http://raventools.com/blog/how-to-vi...t-web-widgets/

I downloaded and installed the Firefox Web Developer add-on:

http://chrispederick.com/work/web-developer/

and by clicking on the 'view generated source' tab, as described in the text, the alphabetized list together with its associated url's is viewable, enabling me to copy and paste out to my own page. Result!

So, without any further need to trouble you (he says whilst holding his breath) I think the problem is solved.

Any feedback you may wish to offer would still be appreciated.
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,291 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
19-Jul-2012, 03:09 AM #14
And that, folks, is a lesson in checking that the website doesn't break your code for you.

These lines
HTML Code:
for (l=0; l<numLines;l++) {
  lines&#91;l&#93; = lines&#91;l&#93;.replace("<","<");
  lines&#91;l&#93; = lines&#91;l&#93;.replace(">",">");
}
are meant to replace the greater and less tags with their HTML code equivalents (< should become & #60; for example). Instead, because you saw it in a browser, the code would replace < with <, not a very useful substitution!

If you change
("<","<") to ("<","& #60;")
and
(">",">") to (">","& #62;")
removing the spaces between & and # it should display as you originally wanted.

Last edited by Ent; 19-Jul-2012 at 03:15 AM..
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 611 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
19-Jul-2012, 03:18 AM #15
Or "&lt;" and "&gt;" of course...

Danny
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2