• User Attivo

    utilizzare filter.js con dati estratti da mysql

    Salve a tutti, non so se sia questa la sezione giusta o dovrei postare nella sezione javascript.

    sto cercando di modificare questo codice trovato in rete

    blog.joshsoftware.com/2011/09/28/filter-js-client-side-search-filtering-using-json-and-jquery/

    per filtrare dei contenuti utilizzando JSON e Jquery, implementandolo con dati estratti da un database mysql tramite php.

    dal sorgente in output del esempio vedo che c'è questo codice

    
    [TABLE]
    
    [TD="class: webkit-line-content"]  <script>[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        //<![CDATA[[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        var services = [[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        {[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "permalink": "1-mr-ona-howe",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "title": "Mr. Ona Howe",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "amount": 100,[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "status": "active",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "is_public": true,[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "id": 1,[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "nonprofit": "Eldon Zulauf"[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        },[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        {[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "permalink": "2-darien-hoeger",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "title": "Darien Hoeger",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "amount": 201,[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "id": 2,[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "status": "inactive",[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]            "nonprofit": "Beryl McDermott"[/TD]
    [/TR]
    
    [TD="class: webkit-line-number"][/TD]
    [TD="class: webkit-line-content"]        },
    .........ecc ecc con tutti i dati........
    //]]>
    </script>[/TD]
    [/TR]
    [/TABLE]
    
    

    dunque io ho pensato di modificare questa parte così

    
      <?php echo "<script>";?>  <?php echo " //<![CDATA[";?>  <?php echo  "    var services = [";?>            <?php
        include("connessione.php");    $query="SELECT * FROM tshirt";    $result = mysql_query($query);    while ($row = mysql_fetch_assoc($result)){        ?>        {            "marca": "<?php echo $row["Marca"]; ?>",            "modello": "<?php echo $row["Modello"]; ?>",            "vendita": "si"        },        <?php }?><?php echo  "];"; ?>  <?php echo" //]]>";?>    <?php echo  "  </script>";?>
    

    come risultato ottengo che l'output è identico ma non mi visualizza i dati estratti. qualcuno sa dirmi in cosa sbaglio? Grazie mille!


  • User Attivo

    chiedo scusa, il problema era in <?php echo " //<![CDATA[";?> <?php echo " var services = [";?> che generava //<![CDATA[ var services = [ su un unica riga, mettendo \n adesso mi fa vedere i risultati