list in alphabetic order

S

steve

I have that list in alphabetic order

<ul>
<li>about some text</li>
<li>be good men</li>
<li>car doors</li>
</ul>

but the list is getting very big and I straggle to keep it in
alphabetic order
can I maybe use some script to display the list in alphabetic order
or how can I achieve that.

Thanks
 
N

Nico Schuyt

steve said:
<ul>
<li>about some text</li>
<li>be good men</li>
<li>car doors</li>
</ul>
can I maybe use some script to display the list in alphabetic order
or how can I achieve that.

If you have some knowledge of PHP and MySQL: Fill a MySQL-table with all the
items and create the list based on a query.
But, that means a lot of work :)
Alternative:
Maintain the list-items as plain text in MS-Word.
Use Word to sort the lines
Copy and paste in a HTML-editor (like FrontPage) and change it there
into a list
Easy and can be done in a few seconds.

Good luck!
 
N

nice.guy.nige

While the city slept, steve ([email protected]) feverishly typed...
I have that list in alphabetic order

<ul>
<li>about some text</li>
<li>be good men</li>
<li>car doors</li>
</ul>

but the list is getting very big and I straggle to keep it in
alphabetic order
can I maybe use some script to display the list in alphabetic order
or how can I achieve that.

Thanks

You can put the list items in an array, sort the array, then step through
the array to display them. In PHP;

<?php
$myList = array("about some text",
"be good men",
"this is not in alpha order",
"car doors",
"aardvarks look silly");

sort($myList);
reset($myList);
print("<ul>\n");
foreach($myList as $listItem) {
print("<li>$listItem</li>\n");
}
print("</ul>\n");
?>

.... then add to the end of the array as and when you have a new item.

Alternatively, you can store the items in a MySQL database table (eg, called
"myItems") then when you get them, specify "sort asc" in the sql statement.

This is straight off the top of my head, not tested, but should at least
point you in the right direction.

Hope that helps,
Nige
 
S

steve

I have that list in alphabetic order
<ul>
<li>about some text</li>
<li>be good men</li>
<li>car doors</li>
</ul>

but the list is getting very big and I straggle to keep it in
alphabetic order
can I maybe use some script to display the list in alphabetic order
or how can I achieve that.

Thanks


Ops
sorry I forgot to mention that there is a links also in the list

<ul>
<li><a href="#">about</a> some text</li>
<li><a href="#">be good men</a></li>
<li><a href="#">car doors</a></li>
</ul>
 
T

Toby Inkster

steve said:
can I maybe use some script to display the list in alphabetic order
or how can I achieve that.

Others have shown how this can be done using server-side scripts. Here's a
client-side way. Note this uses the non-standard (but widely supported)
DOM extension "innerHTML". With a little massaging it could probably be
done in a more standards-compliant way, but it would probably be not as
widely supported.

<ul id="sortme">
<li>football</li>
<li>cricket</li>
<li>snooker</li>
<li>rounders</li>
<li>archery</li>
<li>hockey</li>
</ul>

<script type="text/javascript">
var i, j; // counters
var myarr; // array for sorting things
var listitem; // temporary reference to make things easier to read
var ul; // list to operate on
ul = document.getElementById("sortme");
myarr = new Array();
for (i = 0; i < ul.childNodes.length; ++i) {
listitem = ul.childNodes;
if (listitem.tagName == "LI") {
var t = listitem.innerHTML;
myarr.push(t);
}
}
myarr.sort();
j = 0;
for (i = 0; i < ul.childNodes.length; ++i) {
listitem = ul.childNodes;
if (listitem.tagName == "LI") {
listitem.innerHTML = myarr[j++];
}
}
</script>
 
J

Jukka K. Korpela

steve said:
I have that list in alphabetic order - -
but the list is getting very big and I straggle to keep it in
alphabetic order

Then find a tool that sorts them for you, and use its output as content
of your HTML document. There are lots of such utilities. But beware:
_correctly_ ordering strings is one of the most difficult task in
computing, and naturally requires a useful but exact definition of
"correct order". National standards on ordering may involve rules that
are not implementable algorithmically or _very_ hard to implement.

So what I suggest is: use a suitable tool to get most of the ordering
done automatically, and check and fix the difficult items "by hand".
 
N

Nico Schuyt

steve said:
sorry I forgot to mention that there is a links also in the list
<ul>
<li><a href="#">about</a> some text</li>
<li><a href="#">be good men</a></li>
<li><a href="#">car doors</a></li>
</ul>

Same tric as I mentioned before. This time create a table in Word with 3
columns:
a. ><a href="xxx.htm">
b. Link description
c. >
Sort alfabetically on the second column, paste as plain paragraphs into a
HTML editor and convert to a list.
 
S

steve

Thanks all of you guys
I will test your suggestions and will see which one will be the most
suitable for me
thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top