Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892

    trasformare query in Word

    Salve a tutti,

    io ho la necessità di trasformare il risultato di una query effettuata su db mysql (in forma tabellare) in un file di word, in modo da dare la possibilità all'utente di salvarsela in locale.

    Ho inserito l'header, ma al posto di crearmi un .doc, mi crea un file donwloadabile con estensione .php che contiene il codice html senza peraltro i dati estratti...
    Come mai? posto il codice:

    codice:
    <?php
    header('Content-type: application/msword'); 
    ?>
    <html>
    <body>
    
    <?
    mysql_connect("host", "utente", "pass") or die("Connessione fallita !");
    
    mysql_select_db("miodb") or die("Selezione del DB fallita !");
    
    $count = mysql_query("SELECT COUNT(*) FROM cdr_3 INNER JOIN cdr_2 INNER JOIN cdr_1 INNER JOIN relazio1 INNER JOIN anagrafica INNER JOIN obiettivo ON cdr_2.ID = cdr_3.ide_cdr2 AND relazio1.cdr_2=cdr_2.id AND cdr_1.ID=relazio1.cdr_1 AND anagrafica.id=cdr_3.id_res AND obiettivo.id_cresp=cdr_3.id WHERE obiettivo.descrittore LIKE '%$descrizione%' AND cdr_3.descrizione LIKE '%$cdr3%' AND cdr_1.descrizione LIKE '%$cdr1%'");
    $res_count = mysql_fetch_row($count);
    $tot_records = $res_count[0];
    $per_page = 5;
    $tot_pages = ceil($tot_records / $per_page);
    $current_page = (!$_GET['page']) ? 1 : (int)$_GET['page'];
    $primo = ($current_page - 1) * $per_page;
    $numero=0;
    $query_limit = mysql_query("SELECT DISTINCT cdr_1.descrizione AS descr, cdr_2.descrizione AS desd, cdr_3.descrizione AS miades, anagrafica.cognome, anagrafica.nome, obiettivo.descrittore, obiettivo.indicatore, obiettivo.risorsedesk, obiettivo.risorseuro, obiettivo.pesodir, obiettivo.pesocomp, obiettivo.note FROM cdr_3 INNER JOIN cdr_2 INNER JOIN cdr_1 INNER JOIN relazio1 INNER JOIN anagrafica INNER JOIN obiettivo ON cdr_2.ID = cdr_3.ide_cdr2 AND relazio1.cdr_2=cdr_2.id AND cdr_1.ID=relazio1.cdr_1 AND anagrafica.id=cdr_3.id_res AND obiettivo.id_cresp=cdr_3.id WHERE obiettivo.descrittore LIKE '%$descrizione%' AND cdr_3.descrizione LIKE '%$cdr3%' AND cdr_1.descrizione LIKE '%$cdr1%' GROUP BY cdr_3.id ORDER BY obiettivo.descrittore LIMIT $primo, $per_page");
    while($results = mysql_fetch_array($query_limit))
    
    
     {
    
    $numero=$numero+1;
    ?>
    <div align="center">
      <center>
    
      <table border="0" width="930" height="84">
        <tr>
          <td width="296" height="12"><span class="Stile8"><? print ($results['descr']); ?></span></td>
          <td width="350" height="12"><span class="Stile8"><? print ($results['desd']); ?></span></td>
          <td width="262" height="12"><span class="Stile8"><? print ($results['miades']); ?>
    respons.: <? print ($results['cognome']); ?>, <? print ($results['nome']); ?></span></td>
        </tr>
        <tr>
          <td height="1" colspan="3">
            <p align="center" class="Stile1">Obiettivi di Innovazione e Qualità</td>
        </tr>
      </table>
      </center>
    </div>
    <div align="center">
      <center>
      <table border="0" width="930" height="40">
        <tr>
          <td width="123" height="1"><span class="Stile5">N° <? print $numero; ?></span></td>
          <td width="791" height="1"><span class="Stile5">Descrizione Obiettivo: <? print ($results['descrittore']); ?></span></td>
        </tr>
      </table>
      </center>
    </div>
    <div align="center">
      <center>
      <table border="0" width="931" height="188">
        <tr>
          <td width="312" height="36"><div align="center"><span class="Stile5">Indicatore Obiettivo: </span></div></td>
          <td width="397" height="36"><div align="center"><span class="Stile5">Risorse Necessarie: </span></div></td>
          <td height="36" colspan="2"><div align="center"><span class="Stile5">Peso Dirigenza/Comparto:</span></div></td>
        </tr>
        <tr>
          <td width="312" height="121" rowspan="2"><span class="Stile5"><? print ($results['indicatore']); ?></span></td>
          <td width="397" height="52"><span class="Stile5">umane/tecniche: <? print ($results['risorsedesk']); ?></span></td>
          <td width="103" height="121" rowspan="2"><div align="center"><span class="Stile5">dir. <? print ($results['pesodir']); ?></span></div></td>
          <td width="101" height="121" rowspan="2"><div align="center"><span class="Stile5">comp. <? print ($results['pesocomp']); ?></span></div></td>
        </tr>
        <tr>
          <td height="56"><span class="Stile5">economiche: <? print ($results['risorseuro']); ?> euro </span></td>
        </tr>
    	<tr>
    <td height="32" colspan="4"><span class="Stile5">note: <? print ($results['note']); ?> </span></td>
    	</tr>
      </table>
      </center>
    </div>
    
    
    
    <?
    }
    include("paginazione_7.php");
    echo " $paginazione";
    mysql_close();
    ?>
    </body>
    </html>
    Faccio presente che, oltre a
    header('Content-type: application/msword');
    ho provato anche:
    header('Content-type: application/vnd.ms-word');

    ma il risultato è lo stesso...

  2. #2
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,923
    Prova ad aggiungere questo header dopo quello che hai già
    header ('Content-Disposition: inline; filename="prova.doc" ');

  3. #3
    Nn sono tanto sicuro della cosa xkè nn ho mai affrontato questo problema, cmq credo ke nn dovresti usare la sintassi dell'html ma dell'rtf...se apri un file rtf con il blocco note noterai ke è ben diverso di un file html.
    poi prova a mettere questi header
    header("content-type: application/msword\n");
    header("content-disposition: attachment; filename=nome_del_documento_word");
    header("Cache-control: private");

    queste cose nn le ho pravate ma dovrebbero funzionare

  4. #4

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892
    Ok, perfetto: con questi header funziona!!!

    Grazie mille

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 © 2024 vBulletin Solutions, Inc. All rights reserved.