Files
controls-web/lasuca/inc/excelimport.php
2026-02-17 09:29:34 -06:00

49 lines
1.2 KiB
PHP

<?php
// mysql connection script ...
$dbhost = 'localhost';
$dbuser = 'admin';
$dbpass = 't#23iavs#';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'scdb';
mysql_select_db($dbname);
// tab delimited file
$file = "Lab Worksheet.xls";
// open file
$handle = fopen($file, "r");
$x = 0;
echo "<table border=1>";
// loop through results with fgetcsv() function
while(($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
// populate field vars just to make it easier to work with ..
// you could access the $data[] array directly in the sql if you want
$field1 = $data[0];
$field2 = $data[1];
$field3 = $data[2];
$field4 = $data[2];
// etc ...
// build your sql statement
$sql = "insert into table set
testid='1',
category='foo',
field1='".$field1."',
field2='".$field2."',
field3='".$field3."'";
//if($x >0) $result = mysql_query($sql);
if($x >0) echo "<tr><td>$field1</td><td>$field2</td><td>$field3</td></tr>";
$x++;
}
echo "</table>";
// close file
fclose($handle);
?>