Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2005
    Messaggi
    97

    Visualizzare/Nascondere colonne con php

    Ciao a tutti!
    Sto prearando un gestionale e avrei bisogno di visualizzare o nascondere "sul momento" delle colonne di una tabella (i dati vengono estrapolati da un db).

    Vi posto il codice che permette la visualizzazione dei dati presi da db:

    codice:
    ...
    <?php
    //include database connection
    include 'libs/db_connect.php';
      
    //select all data
    $query = "SELECT id, marchiocommerciale, ragionesociale, sedelegale, indirizzo, cap, citta, prov, nazione, sedeoperativa,
            referente, tel, fax, email, website, pec, codfisc, piva, note, data FROM anagrafica";
    $stmt = $con->prepare( $query );
    $stmt->execute();
      
    //this is how to get number of rows returned
    $num = $stmt->rowCount();
      
    //check if more than 0 record found
    if($num>0){
      
        //start table
        echo "<table border='1'>";
      
            //creating our table heading
            echo "<tr>";
                echo "<th>marchiocommerciale</th>";
                echo "<th>ragionesociale</th>";
                echo "<th>sedelegale</th>";
                echo "<th>indirizzo</th>";
                echo "<th>cap</th>";
                echo "<th>citta</th>";
                echo "<th>prov</th>";
                echo "<th>nazione</th>";
                echo "<th>sedeoperativa</th>";
                echo "<th>referente</th>";
                echo "<th>tel</th>";
                echo "<th>fax</th>";
                echo "<th>email</th>";
                echo "<th>website</th>";
                echo "<th>pec</th>";
                echo "<th>codfisc</th>";
                echo "<th>piva</th>";
                echo "<th>note</th>";
                echo "<th>data</th>";
            echo "</tr>";
      
             
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
                //extract row
                //this will make $row['firstname'] to
                //just $firstname only
                extract($row);
      
                //creating new table row per record
                echo "<tr>";
                          echo "<td>{$marchiocommerciale}</td>";
                echo "<td>{$ragionesociale}</td>";
                echo "<td>{$sedelegale}</td>";
                echo "<td>{$indirizzo}</td>";
                echo "<td>{$cap}</td>";
                echo "<td>{$citta}</td>";
                echo "<td>{$prov}</td>";
                echo "<td>{$nazione}</td>";
                echo "<td>{$sedeoperativa}</td>";
                echo "<td>{$referente}</td>";
                echo "<td>{$tel}</td>";
                echo "<td>{$fax}</td>";
                echo "<td>{$email}</td>";
                echo "<td>{$website}</td>";
                echo "<td>{$pec}</td>";
                echo "<td>{$codfisc}</td>";
                echo "<td>{$piva}</td>";
                echo "<td>{$note}</td>";
                echo "<td>{$data}</td>";
                    echo "<td>";
                        //we will use this links on next part of this post
                        echo "<a href='edit.php?id={$id}'>Edit</a>";
                        echo " / ";
                        //we will use this links on next part of this post
                        echo "<a href='#' onclick='delete_user( {$id} );'>Delete</a>";
                    echo "</td>";
                echo "</tr>";
            }
      
        //end table
        echo "</table>";
      
    }
      
    //if no records found
    else{
        echo "No records found.";
    }
    ?>
    ...
    Vi ringrazio anticipatamente. Buona giornata!
    "perchè la vita è un brivido che vola via...è tutto un'equilibrio sopra la follia!"

  2. #2
    Quote Originariamente inviata da moncicci Visualizza il messaggio
    Ciao a tutti!
    Sto prearando un gestionale e avrei bisogno di visualizzare o nascondere "sul momento" delle colonne di una tabella (i dati vengono estrapolati da un db).

    Vi posto il codice che permette la visualizzazione dei dati presi da db:

    codice:
    ...
    <?php
    //include database connection
    include 'libs/db_connect.php';
      
    //select all data
    $query = "SELECT id, marchiocommerciale, ragionesociale, sedelegale, indirizzo, cap, citta, prov, nazione, sedeoperativa,
            referente, tel, fax, email, website, pec, codfisc, piva, note, data FROM anagrafica";
    $stmt = $con->prepare( $query );
    $stmt->execute();
      
    //this is how to get number of rows returned
    $num = $stmt->rowCount();
      
    //check if more than 0 record found
    if($num>0){
      
        //start table
        echo "<table border='1'>";
      
            //creating our table heading
            echo "<tr>";
                echo "<th>marchiocommerciale</th>";
                echo "<th>ragionesociale</th>";
                echo "<th>sedelegale</th>";
                echo "<th>indirizzo</th>";
                echo "<th>cap</th>";
                echo "<th>citta</th>";
                echo "<th>prov</th>";
                echo "<th>nazione</th>";
                echo "<th>sedeoperativa</th>";
                echo "<th>referente</th>";
                echo "<th>tel</th>";
                echo "<th>fax</th>";
                echo "<th>email</th>";
                echo "<th>website</th>";
                echo "<th>pec</th>";
                echo "<th>codfisc</th>";
                echo "<th>piva</th>";
                echo "<th>note</th>";
                echo "<th>data</th>";
            echo "</tr>";
      
             
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
                //extract row
                //this will make $row['firstname'] to
                //just $firstname only
                extract($row);
      
                //creating new table row per record
                echo "<tr>";
                          echo "<td>{$marchiocommerciale}</td>";
                echo "<td>{$ragionesociale}</td>";
                echo "<td>{$sedelegale}</td>";
                echo "<td>{$indirizzo}</td>";
                echo "<td>{$cap}</td>";
                echo "<td>{$citta}</td>";
                echo "<td>{$prov}</td>";
                echo "<td>{$nazione}</td>";
                echo "<td>{$sedeoperativa}</td>";
                echo "<td>{$referente}</td>";
                echo "<td>{$tel}</td>";
                echo "<td>{$fax}</td>";
                echo "<td>{$email}</td>";
                echo "<td>{$website}</td>";
                echo "<td>{$pec}</td>";
                echo "<td>{$codfisc}</td>";
                echo "<td>{$piva}</td>";
                echo "<td>{$note}</td>";
                echo "<td>{$data}</td>";
                    echo "<td>";
                        //we will use this links on next part of this post
                        echo "<a href='edit.php?id={$id}'>Edit</a>";
                        echo " / ";
                        //we will use this links on next part of this post
                        echo "<a href='#' onclick='delete_user( {$id} );'>Delete</a>";
                    echo "</td>";
                echo "</tr>";
            }
      
        //end table
        echo "</table>";
      
    }
      
    //if no records found
    else{
        echo "No records found.";
    }
    ?>
    ...
    Vi ringrazio anticipatamente. Buona giornata!
    ciao!

    se vuoi farlo al volo lato client, più che php qua si tratta di usare un qualche plugin javascript / jquery / css.
    ad esempio una cosa del genere: https://www.datatables.net/

    PS: poi se posso darti un consiglio personale, tutto quell'html stampato dentro echo non è il massimo.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.