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

    Incolonnamento export PHP->EXCEL

    Buongiorno a tutti,

    ho un piccolo problemino di visualizzazione di un export da PHP ad EXCEL. Sto creando randomicamente 12 squadre che vanno a pescare all'interno di 4 DB e poi esporta il file direttamente in excel, solo che questo procedimento avviene in verticale, cioè mi scrive:

    COLONNA A| COLONNA B|
    Cognome | Squadra|
    x | 1 |
    y | 1 |
    ... | 1 |
    Cognome | Squadra|
    x | 2 |
    y | 2 |
    ... | 2 |

    E così via. Per fare ciò io utilizzo semplicemente la funzione:

    header("Content-Disposition:attachment;filename=file.xls");

    A monte di tutto.

    Ora vorrei sapere c'è un modo che una volta completatata la squadra 1, anzichè continuare sotto vada a scrivere in COLONNA C? Un inserimento orizzontale insomma!

    Grazie dell'aiuto

  2. #2
    certo che si può fare, io lo fatto per esportare i prodotti dei siti e-commerce che fatto creando l'elenco per Danea Easyfatt

    non so adesso come hai scritto il codice sorgente, comunque prima del ciclo while

    bisogna mettere

    Codice PHP:
    echo "
    <table>
    <tr>
    <td>Squadra 1</td>
    <td>Squadra 2</td>
    <td>Squadra 3</td>
    <td>Squadra 4</td>
    <td>Squadra 5</td>
    <td>Squadra 6</td>
    <td>Squadra 7</td>
    <td>Squadra 8</td>
    <td>Squadra 9</td>
    <td>Squadra 10</td>
    <td>Squadra 11</td>
    <td>Squadra 12</td>
    </tr>
    "

    nel ciclo while metti invece

    Codice PHP:
    echo "
    <tr>
    <td>
    $variabile1</td>
    <td>
    $variabile2</td>
    ecc...
    "

    quando chiudi il ciclo while metti

    Codice PHP:
    echo "</table>"
    non so se sono stato chiaro, sembra difficile ma non lo è, se hai problemi postami il codice sorgente che hai scritto
    DigitalWeb Italia - 333.7806821 / info@digitalwebitalia.it

  3. #3
    uhm ora vedo se riesco.
    Dopo le varie connessioni al DB io faccio:


    $query0 = "create temporary table Por as select *,0 as FLG from `Portieri`";
    $restemp=mysql_query($query0);
    $query0 = "create temporary table Dif as select *,0 as FLG from `Difensori`";
    $restemp=mysql_query($query0);
    $query0 = "create temporary table Cen as select *,0 as FLG from `Centrocampisti`";
    $restemp=mysql_query($query0);
    $query0 = "create temporary table Att as select *,0 as FLG from `Attaccanti`";
    $restemp=mysql_query($query0);


    $mul = 1;
    for ($mul = 1; $mul <= 12; ++$mul)
    {

    echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">";
    echo "<tr><th>Cognome</th>";
    echo "<th>Squadra</th></tr>";
    //echo "
    Squadra ".$mul."

    ";

    // portieri
    $query1 = "DROP TABLE IF EXISTS Por2" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query1 = "create temporary table Por2 SELECT * FROM `Por` where FLG = 0 ORDER BY RAND() LIMIT 2" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query2 = "select * from `Por2`";
    $result=mysql_query($query2) or die (mysql_error());

    $query5 = "update `Por` set flg = 1 where id in (select id from `Por2`)";
    $result5=mysql_query($query5) or die (mysql_error());

    while($array=mysql_fetch_array($result))
    {
    echo "<tr><td BGCOLOR=\"LIGHTBLUE\">";
    echo $array['Cognome']."
    ";
    echo "</td><td align=\"center\">";
    echo $mul;
    echo "</td></tr>";

    }

    // difensori
    $query1 = "DROP TABLE IF EXISTS Dif2" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query1 = "create temporary table Dif2 SELECT * FROM `Dif` where FLG = 0 ORDER BY RAND() LIMIT 7" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query2 = "select * from `Dif2`";
    $result=mysql_query($query2) or die (mysql_error());

    $query5 = "update `Dif` set flg = 1 where id in (select id from `Dif2`)";
    $result5=mysql_query($query5) or die (mysql_error());

    while($array1=mysql_fetch_array($result))
    {
    //echo $array1['Cognome']."|".$mul."
    ";
    echo "<tr><td BGCOLOR=\"LIMEGREEN\">";
    echo $array1['Cognome']."
    ";
    echo "</td><td align=\"center\">";
    echo $mul;
    echo "</td></tr>";
    }

    // centrocampisti
    $query1 = "DROP TABLE IF EXISTS Cen2" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query1 = "create temporary table Cen2 SELECT * FROM `Cen` where FLG = 0 ORDER BY RAND() LIMIT 7" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query2 = "select * from `Cen2`";
    $result=mysql_query($query2) or die (mysql_error());

    $query5 = "update `Cen` set flg = 1 where id in (select id from `Cen2`)";
    $result5=mysql_query($query5) or die (mysql_error());

    while($array2=mysql_fetch_array($result))
    {
    //echo $array2['Cognome']."|".$mul."
    ";
    echo "<tr><td BGCOLOR=\"YELLOW\">";
    echo $array2['Cognome']."
    ";
    echo "</td><td align=\"center\">";
    echo $mul;
    echo "</td></tr>";
    }
    // attaccanti
    $query1 = "DROP TABLE IF EXISTS Att2" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query1 = "create temporary table Att2 SELECT * FROM `Att` where FLG = 0 ORDER BY RAND() LIMIT 7" ;
    $result=mysql_query($query1) or die (mysql_error());

    $query2 = "select * from `Att2`";
    $result=mysql_query($query2) or die (mysql_error());

    $query5 = "update `Att` set flg = 1 where id in (select id from `Att2`)";
    $result5=mysql_query($query5) or die (mysql_error());

    while($array3=mysql_fetch_array($result))
    {
    // echo $array3['Cognome']."|".$mul."
    ";
    echo "<tr><td BGCOLOR=\"TOMATO\">";
    echo $array3['Cognome']."
    ";
    echo "</td><td align=\"center\">";
    echo $mul;
    echo "</td></tr>";

    }
    echo "</table>";
    }


    ?>

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