-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
109 lines (89 loc) · 2.39 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("Data-convert.xls");
?>
<html>
<head>
<style>
table.excel {
border-style:ridge;
border-width:1;
border-collapse:collapse;
font-family:sans-serif;
font-size:12px;
}
table.excel thead th, table.excel tbody th {
background:#CCCCCC;
border-style:ridge;
border-width:1;
text-align: center;
vertical-align:bottom;
}
table.excel tbody th {
text-align:center;
width:20px;
}
table.excel tbody td {
vertical-align:bottom;
}
table.excel tbody td {
padding: 0 3px;
border: 1px solid #EEEEEE;
}
</style>
</head>
<body>
<?php
$con=mysqli_connect("localhost","root","","sddr_data");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$letters = range('A', 'Z'); // column letters
$sheet_index = 4;
$table_name = "code_list_lookup";
// echo $data->dump(false, false, $sheet_index);
// loop through sheets
for ($i = 0; $i < $data->colcount($sheet_index); $i++) {
// concatenate strings
$create .= "`".strtolower(
str_replace('/', '',
str_replace(' ', '_', $data->val(1,$letters[$i],$sheet_index))
)
)."` varchar(100) NOT NULL,";
}
// Create table
$createQuery = "CREATE TABLE ".$table_name."(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,".$create."
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;<br/>";
echo $createQuery;
$i = 2;
for ($i; $i <= $data->rowcount($sheet_index); $i++) {
// concatenate strings
// $e .= "`".strtolower(
// str_replace('/', '',
// str_replace(' ', '_', $data->val($i,$letters[$i],$sheet_index))
// )
// )."` varchar(100) NOT NULL,";
if ($i != $i-1) $insert = "";
for ($j = 0; $j < $data->colcount($sheet_index); $j++) {
if ($j != $data->colcount($sheet_index)-1) {
$insert .= "'".mysqli_real_escape_string($con,$data->val($i,$letters[$j], $sheet_index))."', ";
} else {
$insert .= "'".mysqli_real_escape_string($con,$data->val($i,$letters[$j], $sheet_index))."'";
}
}
echo "<br/>INSERT INTO `".$table_name."` VALUES('".$i."', ".$insert.");<br/>";
}
echo $insertQuery;
// Execute query
/*if (mysqli_query($con,$sql)) {
echo "Table persons created successfully";
} else {
echo "Error creating table: " . mysqli_error($con);
}*/
?>
</body>
</html>