2016-05-12 1 views
-3

enter image description here私はSQLテーブルにExcelの表と同じデータを入力したい

Excelの表としてSQLデータテーブルを作成します。 カラム1(N)と列5(圧搾RING FR400(CH7106)、DOOR-12-300)は

+0

これを確認してください:http://stackoverflow.com/questions/36999093/sql-query-to-insert-all-minutes-in-24hour-format-in-a-table/36999258#36999258 ここで私が提供しましたあなたがそれを達成する方法。あなたのニーズに合わせて簡単に編集することができます。 –

答えて

0

をdb.php

<?php 
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error()); 
$db=mysql_select_db('export_db', $conn) or die(mysql_error($conn)); 
?> 

のindex.php

複合主キーであります
<div class="main"> 

<a href="export.php"> Click here to export the database table </a> 

</div> 

export.php

<?php 
include('db.php'); 

//header to give the order to the browser 
header('Content-Type: text/csv'); 
header('Content-Disposition: attachment;filename=exported-data.csv'); 

//select table to export the data 
$select_table=mysql_query('select * from export_table'); 
$rows = mysql_fetch_assoc($select_table); 

if ($rows) 
{ 
getcsv(array_keys($rows)); 
} 
while($rows) 
{ 
getcsv($rows); 
$rows = mysql_fetch_assoc($select_table); 
} 

// get total number of fields present in the database 
function getcsv($no_of_field_names) 
{ 
$separate = ''; 


// do the action for all field names as field name 
foreach ($no_of_field_names as $field_name) 
{ 
if (preg_match('/\\r|\\n|,|"/', $field_name)) 
{ 
$field_name = '' . str_replace('', $field_name) . ''; 
} 
echo $separate . $field_name; 

//sepearte with the comma 
$separate = ','; 
} 

//make new row and line 
echo "\r\n"; 
} 
?> 

このコードに従うことができます。必要に応じて、クエリのデータベース名とtable_nameを置き換えてください。

関連する問題