2016-05-12 7 views
-3

enter image description hereSQL Datentabelle erstellen als Excel-Tabelle

I gleichen Daten als Excel-Tabelle in SQL-Tabelle eingeben möchten. Spalte 1 (N), und Spalte 5 (Austreiber RING FR400 (CH7106), DOOR-12-300) sind zusammengesetzte Primärschlüssel

+0

Überprüfen Sie dieses: http://stackoverflow.com/questions/36999093/sql-query-to-insert-all-minutes-in-24hour-format-in-a-table/36999258#36999258 Hier habe ich zur Verfügung gestellt Methode, wie Sie es erreichen können. Sie könnten es einfach für Ihre Bedürfnisse bearbeiten. –

Antwort

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"; 
} 
?> 

Sie können diesem Coding folgen. Ersetzen Sie einfach den Datenbanknamen und Tabellenname in der Abfrage nach Ihren Bedürfnissen.

Verwandte Themen