-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
64 lines (63 loc) · 2.02 KB
/
index.php
File metadata and controls
64 lines (63 loc) · 2.02 KB
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
<?php
$db = new mysqli('localhost','root','','test');
if ($db->connect_errno) {
echo "Failed to connect to MySQL: " . $db->connect_error;
exit();
}
?>
<table align="center" width="800" border="1" style="border-collapse:collapse; border:1px solid #ddd;" cellpadding="5" cellspacing="0">
<thead>
<tr bgcolor="#FFCC00">
<th>Country Code</th>
<th>Country Name</th>
<th>Currency Code</th>
<th>Population</th>
<th>Fips Code</th>
<th>ISO Numeric</th>
<th>North</th>
<th>South</th>
<th>East</th>
<th>West</th>
<th>Capital</th>
<th>Continent Name</th>
<th>Continent</th>
<th>Area In Sq Km</th>
<th>ISO Alpha 3</th>
<th>Geoname Id</th>
</tr>
</thead>
<tbody>
<?php
if(($handle = fopen("countries.csv", "r")) !== FALSE){
$n = 1;
while(($row = fgetcsv($handle)) !== FALSE){
$db->query('INSERT INTO `countries`(`countryCode`, `countryName`, `currencyCode`, `population`, `fipsCode`, `isoNumeric`, `north`, `south`, `east`, `west`, `capital`, `continentName`, `continent`, `areaInSqKm`, `isoAlpha3`, `geonameId`) VALUES ("'.$row[1].'","'.$row[2].'","'.$row[3].'","'.$row[4].'","'.$row[5].'","'.$row[6].'","'.$row[7].'","'.$row[8].'","'.$row[9].'","'.$row[10].'","'.$row[11].'","'.$row[12].'","'.$row[13].'","'.$row[14].'","'.$row[15].'","'.$row[16].'")');
if($n>1){
?>
<tr>
<td><?php echo $row[1];?></td>
<td><?php echo $row[2];?></td>
<td><?php echo $row[3];?></td>
<td><?php echo $row[4];?></td>
<td><?php echo $row[5];?></td>
<td><?php echo $row[6];?></td>
<td><?php echo $row[7];?></td>
<td><?php echo $row[8];?></td>
<td><?php echo $row[9];?></td>
<td><?php echo $row[10];?></td>
<td><?php echo $row[11];?></td>
<td><?php echo $row[12];?></td>
<td><?php echo $row[13];?></td>
<td><?php echo $row[14];?></td>
<td><?php echo $row[15];?></td>
<td><?php echo $row[16];?></td>
</tr>
<?php
}
$n++;
}
fclose($handle);
}
?>
</tbody>
</table>