HTML
  Home arrow HTML arrow Page 3 - Sorting for Database Forms with HTML
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Sorting for Database Forms with HTML
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-08-13

    Table of Contents:
  • Sorting for Database Forms with HTML
  • The sort() Function continued
  • The getColumnIndex() Function
  • The titleBoolArr Array

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sorting for Database Forms with HTML - The getColumnIndex() Function


    (Page 3 of 4 )

    This function returns the column index. It takes the title of the recordset column as an argument. The titles for the columns are ID, Name, Department, Job, Years, and Salary. The index it returns is a value from 0 to 5. This is the function:


    function getColumnIndex(title)

    {

    for (i=0; i<6; i++)

    {

    if(titleBoolArr[i][0] == title)

    return i;

    }

    return 6;

    }


    The titleBoolArr array in the function has been designed in such a way that the recordset column index is the row index of the titleBoolArr array. The above function is self-explanatory.

    The quickSort() Function

    This is the function that actually does the sorting. It receives the first row index (0) of the recordset, the last row index (numberOfRows - 1) of the recordset, and the column index (titleInx) for a column in the recordset as parameters. The sorting takes place based on a column (titleInx). The quickSort() function does not return any value; it rearranges the rows of the recordset in ascending order based on a column. As I said above, if you want to understand how the function operates, read one of my previous articles, titled “Quicksort.” However, this is the function:


    function quickSort(left,right,titleInx)

    {//the function receives a recordset, indices for the left and right rows, and the index for the title column.

    i = left;

    j = right;


    if(document.getElementById('Recordset').rows[i].cells[titleInx].innerHTML > document.getElementById('Recordset').rows[j].cells[titleInx].innerHTML)

    {

    swap(i, j);

    }


    do //increment i and decrement j, then swap if necessary

    {

    do

    {

    if ((i+1)<=right) //do not increment i beyond the index for the right element

    {

    ++i;

    }

    } while (document.getElementById('Recordset').rows[i].cells[titleInx].innerHTML < document.getElementById('Recordset').rows[left].cells[titleInx].innerHTML)

    do

    {

    if ((j-1)>=left) //do not decrement j beyond the index for the left element

    {

    --j;

    }

    } while (document.getElementById('Recordset').rows[j].cells[titleInx].innerHTML > document.getElementById('Recordset').rows[left].cells[titleInx].innerHTML)

     

    if (i<j)

    {

    swap(i, j);

    }

    } while (i < j)


    swap(j, left);

    var k = j; //the pivot.

     

    var leftLeft = left; //the index for the left element of the left sub-list, initialized

     

    if ((k-1)>=left) //we do not want a value for k that will be less than the left index

    {

    var leftRight = k - 1; //the index for the right element of the left sub-list, initialized

    }

    if ((k+1)<=right) //we do not want a value for k that will be greater than the right index

    {

    var rightLeft = k + 1; //the index for the left element of the right sub-list, initialized

    }

    var rightRight = right; //the index for the right element of the right sub-list, initialized



    //recursion for the left sub-list - only called if a left sub-list exists

    if (k != left)

    {

    quickSort(leftLeft,leftRight,titleInx);

    }

     

    //recursion for the right sub-list - only called if a right sub-list exists

    if (k != right)

    {

    quickSort(rightLeft,rightRight,titleInx);

    }

    }


    The recordset is like a two dimensional array. The quickSort() function is slightly different from the one I wrote in the article titled, "Quicksort." In that article, sorting is done only for a one-dimensional array. Here, the function is different, because the two dimensional array aspects have to be taken into consideration.

    Note that after the sorting is done, the result stays in memory. If you exit the program and start again the resultset will be in its original state.

    There is a corresponding function to quickSort(), called swap(). The swap() function takes in two parameters that are the indices of the recordset rows to be swapped. It swaps the contents of the two rows. This is the function:


    function swap(m,n)

    {

    for (z=0; z<7; z++)

    {

    temp = document.getElementById('Recordset').rows[m].cells[z].innerHTML;

    document.getElementById('Recordset').rows[m].cells[z].innerHTML = document.getElementById('Recordset').rows[n].cells[z].innerHTML;

    document.getElementById('Recordset').rows[n].cells[z].innerHTML = temp;

    }

    }

    More HTML Articles
    More By Chrysanthus Forcha


       · We have gone this far! There can be no turning back.Chrys
     

    HTML ARTICLES

    - Hello HTML 5, Goodbye Gears
    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek