How can I import a file (csv / excel) with partial data into a table in a database via phpmyadmin?

I needed updated customer information to populate the customer table.

I exported the table in which I wanted to get the excel file, and asked them to fill in the new information (it was only the column that I needed was updated), and they sent me the file back.

Now I want to import this information back into the table column.
Trial and error many times, is converted to a csv excel file and imported via phpmyadmin.

But he did not update a single column.

What am I doing wrong?

+3
source share
3 answers

UPDATE CSV-, FOSS CSV, CSVFix, , , PHP .

+4

.csv, - PHP, script, / .

, , csv :

id,name,address,email,date

:

1,bob smith,344 abc street,test@example.com,2009-04-01

:

<?php
$data=file_get_contents('your-file.csv');
//Split the file and get an array representing the lines/rows in the .csv
$rows=explode("\n",$data); 

foreach ($rows as $row)
{

   //Remove any excess whitespace from start and end of the row:
   $row=trim($row);
   $id=$row[0];
   $name=$row[1];
   $address=$row[2];
   $email=$row[3];
   $date=$row[4];
   mysql_query("UPDATE TABLE SET name='$name',....);
}
?>
+2

PHP fgetcsv() CSV .

, CSV MySQL. mysql_query(), PHPMyAdmin.

+1

Source: https://habr.com/ru/post/1706957/


All Articles