My client got a excel file with the following structure
name | email
----------------------------
Name | email here
Name | email here
Name | email here
Name | email here
Name | email here
Name | email here
I would likes to make a MySQL database table according to this pattern and save the data into MySQL.
I am wonder how to do this. Also there is an option needed
We have to check that if that corresponding user had a correct email address, ie of the form @ .
Can we check the data as a loop while importing ?
Also how to convert this data to MySQL ?
Save this excel file as csv and run the following code with add your changings
$source = fopen('email.csv', 'r') or die("Problem open file");
while (($data = fgetcsv($source, 1000, ",")) !== FALSE)
{
$name = $data[0];
$email = $data[1];
mysql_query("INSERT INTO `table` (`name`,`email`) VALUES ('".$name."','".$email."') ");
}
fclose($source);
There is a
Iibrary named PHPExcel. With this library you can easily parse any excel file. Or you can export your file as csv and will be easier for you. php has native functions to handle csv files. You can use fgetcsv()
or str_getcsv()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With