list in alphabetic order

Discussion in 'HTML' started by steve, Sep 26, 2004.

  1. steve

    steve Guest

    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
     
    steve, Sep 26, 2004
    #1
    1. Advertising

  2. steve

    Nico Schuyt Guest

    steve wrote:
    > <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!
    --
    Nico
    www.nicoschuyt.nl
     
    Nico Schuyt, Sep 26, 2004
    #2
    1. Advertising

  3. While the city slept, steve () 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

    --
    Nigel Moss
    http://www.nigenet.org.uk
    Mail address not valid. , take the DOG. out!
    In the land of the blind, the one-eyed man is very, very busy!
     
    nice.guy.nige, Sep 26, 2004
    #3
  4. steve

    steve Guest

    > 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>
     
    steve, Sep 26, 2004
    #4
  5. steve

    Toby Inkster Guest

    steve wrote:

    > 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>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Sep 26, 2004
    #5
  6. "steve" <> wrote:

    > 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".

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Sep 26, 2004
    #6
  7. steve

    Nico Schuyt Guest

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

    > 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.

    --
    Nico
    www.nicoschuyt.nl
     
    Nico Schuyt, Sep 27, 2004
    #7
  8. steve

    steve Guest

    Thanks all of you guys
    I will test your suggestions and will see which one will be the most
    suitable for me
    thanks again
     
    steve, Sep 27, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    MAJOR problem with alphabetic paging

    =?Utf-8?B?VGltOjouLg==?=, Jul 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    500
    =?Utf-8?B?VGltOjouLg==?=
    Jul 26, 2005
  2. py_genetic
    Replies:
    6
    Views:
    331
    py_genetic
    Jun 19, 2007
  3. emre esirik(hacettepe computer science and enginee

    I want to list data by alphabetic

    emre esirik(hacettepe computer science and enginee, Dec 2, 2007, in forum: C Programming
    Replies:
    7
    Views:
    335
    Bill Reid
    Apr 9, 2008
  4. Sandhya Prabhakaran
    Replies:
    6
    Views:
    609
    alex23
    Aug 3, 2009
  5. Ian Richardson

    true alphabetic sort...

    Ian Richardson, Apr 24, 2004, in forum: Javascript
    Replies:
    13
    Views:
    1,019
    Thomas 'PointedEars' Lahn
    May 5, 2004
Loading...

Share This Page