www.webdeveloper.com
Results 1 to 3 of 3

Thread: Sort Table from Header

  1. #1
    Join Date
    Apr 2008
    Posts
    2

    Sort Table from Header

    Hi to everybody.
    I've a little problem....
    I've this function:

    PHP Code:
     
    Function VisualizzaTabellaFooter($elencotabelle,$criterioricerca,$testodescrizione){ 
    INCLUDE(
    'config.php'); 
    ################################### 
    //Function which visualizes the data contained in the table listini. They come visualizes to you in 
    //one table that has lines of alternated color, click heading in order to sorting
    ############################################################# 
    $connessione mysql_connect($db_host$db_user,$db_password) or die("Connessione fallita !"); 
    @
    mysql_select_db($db_name) or die("Selezione Database fallita !"); 
     
    $testodescrizione=$_GET['testodescrizione']; 
    $elencotabelle=$_GET['elencotabelle']; 
     
    if (isset(
    $_GET['field'])) { 
    $campo $_GET['field'] == "descrizione" "descrizione" "Codice_articolo" 
    } else { 
    $campo "Costruttore"

    if (isset(
    $_GET['sort'])) { 
    $verso $_GET['sort'] == "desc" "DESC" "ASC"
    } else { 
    $verso "ASC"

     
    if ((
    $elencotabelle=="listini" and  $testodescrizione="")or ($elencotabelle=="costruttori" or $elencotabelle=="categorie")){ 
              
    //print whole listini table
     
    $sql="SELECT * from listini order by {$campo} {$verso}  "
     
    $risultato_query=mysql_query($sql,$connessione)or die ("query 1 fallita"); 
                                 
                                } 
     
    else{   
     
        
    // print listini table whit FILTER based on WHERE condition
         
        
    $word=trim($_GET['testodescrizione']); 
     
        
    $sql1="SELECT * from listini where Codice_articolo like \"%$word%\"   order by {$campo} {$verso} 
    "

        
    $risultato_query=mysql_query($sql1,$connessione)or ("Query sbagliata " .mysql_error()); 
         
    // controlla il risultato della query attraverso la funzione mysql_query 

     
    $res_count=mysql_num_rows($risultato_query); 
    // numero totale di records 
     
    $verso = ($verso == "ASC") ? "desc" "asc"
     
      echo 
    "<table width=\"747\" border=\"1\"> 
     <tr> 
       <td width=\"118\"class=\"intestazione\"width=\"223\"><a href='index.php?field=Costruttore&sort=
    {$verso}'>Costruttore 
       </a></td> 
     
       <td width=\"164\" class=\"intestazione\"width=\"223\"><a href='index.php?field=Codice_articolo&sort=
    {$verso}'>Codice_articolo</a></td> 
     
       <td width=\"149\" class=\"intestazione\"width=\"223\"><a href='index.php?field=descrizione&sort=
    {$verso}'>descrizione</a></td> 
     
       <td width=\"141\"class=\"intestazione\"width=\"223\"><a href='index.php?field=listino&sort=
    {$verso}'>listino</td> 
     
       <td width=\"141\"class=\"intestazione\"width=\"223\"><a href='index.php?field=Codice Barcode&sort=
    {$verso}'>Codice Barcode</td> 
     
     </tr> 
    </table>"

         echo
    " <div id=\"Layer1\"  style=\" width:747px; height:115px; overflow: auto;\"> "
    $class ''
     
    while(
    $riga=mysql_fetch_array($risultato_query)){ 
          
                  
    $Costruttore=$riga["Costruttore"]; 
                 
    $Codice_articolo=$riga["Codice_articolo"]; 
                 
    $descrizione=$riga["descrizione"]; 
                  
    $listino=$riga["listino"]; 
                  
    $barcode=$riga["codice_barcode"]; 
                  
                 
    $class $class == 'colore1' 'colore2' 'colore1'
              
    echo 
    "<table width=\"747\" border=\"1\">"
                 echo
    " <tr class= \"$class\"> "
     
        echo
    " <td  width=\"118\" class= \"$class\" >$Costruttore </td>"
        echo
    "<td    width=\"164\" >$Codice_articolo</td>"
         echo
    "<td    width=\"149\" >$descrizione</td>"
         echo
    "<td    width=\"141\" >$listino</td>"
         echo
    "<td    width=\"141\" >$barcode</td>"
        echo
    "</tr>"
             } 
             echo
    "</table>"
           echo
    "</div>"
    echo
    "</td>"
      echo
    " </tr>"
    echo
    "</body>"
    echo
    "</html>"

    The function is OK when it is in the first if. That is Press all the table ' listini' and making click on the columns ALL TABLE SORT ITSSELF, on that field. When instead we are in the else, the FILTER works good with the WHERE condition, but MAKING CLICK On the COLUMNS, GIVES BACK to ALL the RECORDS to ME Of the TABLE, INDIFFERENTLY, WITHOUT FILTER. How I can arrange it? Thanks!

  2. #2
    Join Date
    Aug 2007
    Location
    Leeds, Yorkshire, England
    Posts
    387
    Buona sera panta rei, come va?

    You might take a look at this for a js solution: http://www.workingwith.me.uk/article..._table_sorting

  3. #3
    Join Date
    Apr 2008
    Posts
    2
    Hi, Thanks for your answer. Grazie
    I have seen that link, but I don't need that

    In effects my problem is just that one. The SORTING WHEN IT MAKE The SECOND QUERY Of the ELSE.
    The 2 query work ok.
    You can see the example of my test here: http://www.ctedintorni.altervista.org/listini/index.php.
    If you open with firefox, and you put in listini as an example, codice, a10, will appear 11 records in the below table.

    But when I try to make the ordering, it show of all 300 present ones, so it does not respect the condition of WHERE. You have suggestions on like arranging the code of over? Thanks! I'm just blocked.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles