我正在尝试将我的数据从 mysql 传输到 ms-excel 它的工作,但我使用 php 获取重复值
<?php
$form='';
$link = odbc_connect ('Ayush', '', '');
if (!$link)
{
die('Could not connect: ' . odbc_error());
}
echo 'Connected successfully .<br>';
//create query to select as data from your table
$sql= "SELECT * FROM adel";
$result = odbc_exec($link,$sql);
$sep = "\t"; //tabbed character
$fp = fopen('database.xls', "w");
$schema_insert = "";
$schema_insert_rows = "";
for ($i = 1; $i < (odbc_num_fields($result))+1; $i++)
{
$schema_insert_rows.=odbc_field_name($result,$i) . "\t";
}
$schema_insert_rows.="\n";
echo $schema_insert_rows;
fwrite($fp, $schema_insert_rows);
//start while loop to get data
while($row = odbc_fetch_array($result))
{
foreach($row as $value)
{
//set_time_limit(60); //
/*$schema_insert = "";
for($j=1; $j<odbc_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "") */
$schema_insert.= strip_tags("$value").$sep;
$schema_insert .= "";
}
//$schema_insert = str_replace($sep."$", "", $schema_insert);
//this corrects output in excel when table fields contain \n or \r
//these two characters are now replaced with a space
//$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\n";
//$schema_insert = (trim($schema_insert));
//print $schema_insert .= "\n";
print "\n";
fwrite($fp, $schema_insert);
}
fclose($fp);
odbc_close($link);
?>
输出如下
我不想要任何重复的值谁能帮助我
真的很感激
谢谢