Impossible de download / traiter sql pour excel à l'aide de PHP

J'ai eu cette question étrange. Je souhaite exécuter un script qui récupère datatables à partir d'une table et télécharge le format Excel en utilisant un script php. Il fonctionne correctement sur la machine locale mais ne fonctionne pas sur le server linux. J'ai essayé sur 2 servers différents, mais aucun n'a fonctionné. Voici le code.

<?php include "config.php"; $count = 0; $sqlquery = "select * from contact_us" ; $result = mysql_query($sqlquery) or die(mysql_error()); $count = mysql_num_fields($result); for ($i = 0; $i < $count; $i++) { $header .= mysql_field_name($result, $i)."\t"; } while($row = mysql_fetch_row($result)) { $line = ''; foreach($row as $value) { if(!isset($value) || $value == "") { $value = "\t"; } else { # important to escape any quotes to preserve them in the data. $value = str_replace('"', '""', $value); # needed to encapsulate data in quotes because some data might be multi line. # the good news is that numbers remain numbers in Excel even though quoted. $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= sortingm($line)."\n"; } # this line is needed because returns embedded in the data have "\r" # and this looks like a "box character" in Excel $data = str_replace("\r", "", $data); # Nice to let someone know that the search came up empty. # Otherwise only the column name headers will be output to Excel. if ($data == "") { $data = "\nno matching records found\n"; } $count = mysql_num_fields($result); # This line will stream the file to the user rather than spray it across the screen header("Content-type: application/vnd.ms-excel"); //header("Content-type: text/plain"); # replace excelfile.xls with whatever you want the filename to default to header("Content-Disposition: attachment; filename=excelfile.xls"); header("Pragma: no-cache"); header("Expires: 0"); //echo $header."\n".$data; echo $header."\n".$data."\n"; ?> 

Un autre code que j'ai essayé, mais montre la valeur au lieu de download le format Excel

  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> inclure "config.php";  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> ?>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> $ i = 0;  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> ?>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> <thead>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> <th> Ville </ th>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> ?>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> <? php}?>  <?php include "config.php"; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="MasterEntryList.xls"'); ?> <?php $i=0; if(isset($_POST['dsubmit'])) { $pro=$_POST['project']; if(($_POST['fromdate']=="") || ($_POST['todate']=="")) { $fromdate=""; $todate=""; $date = ""; } else { $fromdate=$_POST['fromdate']; $todate=$_POST['todate']; $date = "yes"; } //Start Single Condition if( ($pro!="") && ($date=="") ) { $cond="WHERE project_ LIKE '$pro'"; }else if(($pro=="") && ($date!="") ) { $cond="WHERE (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro!="") && ($date!="") ) { $cond="WHERE project_ LIKE '$pro' AND (date_ BETWEEN '$fromdate' AND '$todate')"; }else if( ($pro=="") && ($date=="") ) { $cond=" "; } $sql="SELECT * FROM contact_us {$cond}"; $query=mysql_query($sql); } else { $query=mysql_query("SELECT * FROM contact_us order by id DESC Limit 100 "); } ?> <table class="table table-ssortingped table-bordered table-hover" id="dataTables-example" border="1"> <thead> <tr> <th> Sr.No.</th> <th>Client Name</th> <th>Country Code</th> <th>Contact</th> <th>City</th> <th>UTM Campaign</th> <th>UTM Source</th> <th>UTM medium</th> <th>Date</th> </tr> </thead> <tbody> <?php $follow=date("Ymd"); while( $result_data=mysql_fetch_assoc($query) ) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td><?php if($result_data['name_']==""){echo "NA";}else {echo $result_data['name_'];}?> </td> <td><?php if($result_data['country_']==""){echo "00";}else {echo $result_data['country_'];}?></td> <td><?php if($result_data['number_']==""){echo "0000000000";}else {echo $result_data['number_'];}?></td> <td><?php if($result_data['city_']==""){echo "NA";}else {echo $result_data['city_'];}?></td> <td><?php if($result_data['utm_campaign']==""){echo "NA";}else {echo $result_data['utm_campaign'];}?></td> <td><?php if($result_data['utm_source']==""){echo "NA";}else {echo $result_data['utm_source'];}?></td> <td><?php if($result_data['utm_medium']==""){echo "NA";}else {echo $result_data['utm_medium'];}?></td> <td><?php if($result_data['date_']==""){echo "0000-00-00";}else {echo $result_data['date_'];}?></td> </tr> <?php } ?> </tbody> </table> 

Cela peut vous aider

Utilisez les fonctions mysqli_* car les fonctions mysql_* sont anciennes maintenant.

 function export_to_excel($array, $filename="test.xls", $delim = "\t", $newline = "\n", $enclosure = '"' ) { $ssortingng_to_export = ""; $c = 0; foreach( $array as $row) { // Header if(!$c) { $ssortingng_to_export .= $enclosure.implode($enclosure.$delim.$enclosure, array_keys($row) ).$enclosure.$newline; } $ssortingng_to_export .= $enclosure.implode($enclosure.$delim.$enclosure, array_values($row) ).$enclosure.$newline; $c++; } header('Content-type: application/vnd.ms-excel;charset=utf-8'); header('Content-Disposition: attachment; filename='.$filename); header("Cache-Control: no-cache"); echo $ssortingng_to_export; die(); } $link = mysqli_connect("host", "user", "password", "db"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $sqlquery = "select * from contact_us" ; if ($result = mysqli_query($link, $sqlquery)) { // php 5.3 + if you have then // use mysqli_fetch_all function otherwise mysqli_fetch_assoc while ($row = mysqli_fetch_assoc($result)) { $array[] = $row; } export_to_excel($array); }