Ciao a tutti come al solito problemi, allora devo prendere dei dati dal database e metterli in un file excel. Con questo codice qui sotto sono riuscito a farlo, cioe prendo una tabella e la stampo dentro il file.xls. Il mio problema è che non so come fare nel momento in cui devo prendere dati da un'altra tabella e scriverli nello stesso file di prima. Quindi come fare in modo di avere un file ma con dentro 2 fogli.

Codice PHP:
<?php 
$DB_Server 
"localhost";        //your MySQL Server 
$DB_Username "root";                 //your MySQL User Name 
$DB_Password "";                //your MySQL Password 
$DB_DBName "portale";                //your MySQL Database Name 
$DB_TBLName "jos_users";                //your MySQL Table Name 
$DB_TBLName2 "jos_session";

$sql "Select * from $DB_TBLName"

//create MySQL connection 
$Connect = @mysql_connect($DB_Server$DB_Username$DB_Password
     or die(
"Couldn't connect to MySQL:
mysql_error() . "
mysql_errno()); 
//select database 
$Db = @mysql_select_db($DB_DBName$Connect
     or die(
"Couldn't select database:
mysql_error(). "
mysql_errno()); 
//execute query 
$result = @mysql_query($sql,$Connect
     or die(
"Couldn't execute query:
mysql_error(). "
mysql_errno()); 


$file_type "vnd.ms-excel"
$file_ending "xls"

//header info for browser: determines file type ('.doc' or '.xls') 
header("Content-Type: application/$file_type"); 
header("Content-Disposition: attachment; filename=prova1.$file_ending"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 

/*    Start of Formatting for Word or Excel    */ 

     //define separator (defines columns in excel & tabs in word) 
     
$sep "\t"//tabbed character 

     //start of printing column names as names of MySQL fields 
     
for ($i 0$i mysql_num_fields($result); $i++) 
     { 
         echo 
mysql_field_name($result,$i) . "\t"
     } 
     print(
"\n"); 
     
//end of printing column names 

     //start while loop to get data 
     
while($row mysql_fetch_row($result)) 
     { 
         
//set_time_limit(60); // HaRa 
         
$schema_insert ""
         for(
$j=0$j<mysql_num_fields($result);$j++) 
         { 
             if(!isset(
$row[$j])) 
                 
$schema_insert .= "NULL".$sep
             elseif (
$row[$j] != ""
                 
$schema_insert .= "$row[$j]".$sep
             else 
                 
$schema_insert .= "".$sep
         } 
         
$schema_insert str_replace($sep."$"""$schema_insert); 
         
$schema_insert preg_replace("/\r\n|\n\r|\n|\r/"" "$schema_insert); 
         
$schema_insert .= "\t"
         print(
trim($schema_insert)); 
         print 
"\n"
     } 

?>