Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Creare tabella e salvarla in formato excel

    Ciao a tutti,
    è un argomento che è stato trattato qui sul forum ma non sono riuscito a far funzionare il tutto.
    Lo script che segue genera correttamente un file excel ma è sempre vuoto (contiene solo le intestazioni delle colonne).

    Codice PHP:
    <?php
    header
    ('Content-type: application/vnd.ms-excel');
    header("Content-disposition: attachment;filename=nomefile.xls");
    $filename="export.xls";
    ?>

    <!-- iniziamo a costruire la nostra tabella --/>
    <html><head><title>Export</title></head><body>
    <table border="1">
    <tr>
    <th>Data registrazione</th>
    <th>Nome</th>
    <th>Cognome</th>
    <th>Segnalatore</th>
    <th>Tutor</th>
    <th>Servizio inviante</th>
    <th>Stato</th>
    </tr>
    <?
    require_once('config.php');
    $link mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
    if(!
    $link) {
    die(
    'Failed to connect to server: ' mysql_error());
    }
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }
    $sql="select data_reg, nome, cognome, segnalatore, tutor, servinviante, stato FROM utenti  WHERE idunivoco LIKE 'GVN%' ORDER BY data_reg ASC"
    $query=@mysql_query($sql) or die (mysql_error());
    while (
    $row=mysql_fetch_array($query)) 
    {
    $data_reg=$row['data_reg'];
    $nome=$row['nome'];
    $cognome=$row['cognome'];
    $segnalatore=$row['segnalatore'];
    $tutor=$row['tutor'];
    $servinviante=$row['servinviante'];
    $stato=$row['stato'];
    ?>
    <tr>
    <td><? echo $data_reg?></td>
    <td><? echo $nome?></td>
    <td><? echo $cognome?></td>
    <td><? echo $segnalatore?></td>
    <td><? echo $tutor?></td>
    <td><? echo $servinviante?></td>
    <td><? echo $stato?></td>
    </tr>
    <?
    }
    ?>
    </table>
    </body>
    </html>
    <?
    @mysql_close($link);
    ?>
    Avete qualche idea in merito?

    Grazie!!!

    Tulipano

  2. #2
    Ho provato anche a modificare il tipo di file (txt/csv ma non va uguale...stesso comportamento).
    Ho inoltre eseguito la query e funziona (mi tira fuori i risultati).

    Hmmmm....

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.