0

I'm trying to sort out a movie listing webpage that lists all the movies in sequence according to their #TITLE#. Currently the software automatically generates a web page based off of a template file. Below is the portion of the coding in the template file that lists the movies:

 <!-- Latest additions-->
#LATEST_ADDITIONS_START#
<div class="header">Movie Cover Listings</div>
#LATEST_ADDITIONS_TEMPLATE_START#
<li>
    <a href="movies/#INDEX#.htm">
    <table style="display: inline; border: 0; cellspacing: 1;">
        <tr align="center">
            <td align="center"><img border="0" src="covers/#COVER#.jpg" width="#WIDTH#" height="#HEIGHT#"></td>
        </tr>
        <tr align="center">
            <td width="80" height="100" align="center" valign="top">#TITLE#</td>
        </tr>
    </table>
</a>
</li>
#LATEST_ADDITIONS_TEMPLATE_END#
<div class="link_latest"><tr>#LATEST_ADDITIONS#</tr></div>
#LATEST_ADDITIONS_END#

<!-- All movies -->

This is what the programs generates from the database using the template file:

<!-- Latest additions-->

<div class="header">Movie Cover Listings</div>

<div class="link_latest"><tr>

<li>
    <a href="movies/2.htm">
    <table style="display: inline; border: 0; cellspacing: 1;">
        <tr align="center">
            <td align="center"><img border="0" src="covers/000002.jpg" width="90" height="135"></td>
        </tr>
        <tr align="center">
            <td width="80" height="100" align="center" valign="top">3 Days to Kill</td>
        </tr>
    </table>
</a>
</li>

<li>
    <a href="movies/1.htm">
    <table style="display: inline; border: 0; cellspacing: 1;">
        <tr align="center">
            <td align="center"><img border="0" src="covers/000001.jpg" width="89" height="135"></td>
        </tr>
        <tr align="center">
            <td width="80" height="100" align="center" valign="top">300: Rise of an Empire 3D</td>
        </tr>
    </table>
</a>
</li>
</tr></div>


<!-- All movies -->

As you can see it orders it automatically in numerical descending order by #INDEX# file name. I want to order it alphabetically by #TITLE# name.

Does anyone have a clue how to do that?

Thank you for the help.

Aaron C
  • 9
  • 3

2 Answers2

0

You are getting all your values from the backend database which is show all values in Descending Order by DESC file_name.

If you want to show all data order by title name, you simply needs to do this:

SELECT * FROM table_name ORDER BY title_name DESC

John Smith
  • 39
  • 1
  • 7
  • Just change ORDER BY file name to ORDER BY title_name and if u want to show in Descending Order then after ORDER BY title_name put DESC. Follow above instructions then I am sure you will get it work.. – John Smith Feb 08 '15 at 07:47
0

If this can be done on backend, I would suggest using ORDER BY clause:

SELECT * FROM table_name ORDER BY title

This would be more efficient than using it on frontend. But since the question has tags related to frontend only:

function sortUnorderedList(ul, sortDescending) {
  if(typeof ul == "string")
    ul = document.getElementById(ul);

  // Get the list items and setup an array for sorting
  var lis = ul.getElementsByTagName("LI");
  var vals = [];

  // Populate the array
  for(var i = 0, l = lis.length; i < l; i++)
    vals.push(lis[i].innerHTML);

  // Sort it
  vals.sort();

  // Sometimes you gotta DESC
  if(sortDescending)
    vals.reverse();

  // Change the list on the page
  for(var i = 0, l = lis.length; i < l; i++)
    lis[i].innerHTML = vals[i];
}

//Easy to use...

sortUnorderedList("ID_OF_LIST");

Reference: How may I sort a list alphabetically using jQuery?

Community
  • 1
  • 1
softvar
  • 17,917
  • 12
  • 55
  • 76
  • I can only edit the front end (or the template web page). The program generates all the #""# output data and the program translates the web page template to a webpage. This is why I'm stuck. – Aaron C Feb 08 '15 at 08:11
  • Still doesn't work. I'm probably doing something wrong but I can't tell. I'm still kinda a newbie to advanced javascript. I can get basic javascript and even a bit advanced as well as working with a fresh page. But when it comes to rewriting a page(s) layout (especially those with no java in them to start) using javascript I'm a bit lost. – Aaron C Feb 08 '15 at 08:24