I do Hope someone can help, I have a table with 7 columns ( All Empty )
id | unqid | Numbers | Date/Time | IP | UserAgent | Confirmed
Basically what im trying to do in php is browse for my CSV File with a single column of numbers, Then upload and isert the numbers from the CSV into The Numbers Column in mysql Table.
I have done this with php by simply submitting 1 number.
mysql_query("INSERT test_mysql SET number='$number', uid='$uid'") or die(mysql_error());
but i have serached high and low and tried many examples and tried myself but im getting nowhere.
There will be proper libraries to do this but given a simple csv file
a,b,c
1,2,3
4,5,6
then you can loop through it as demonstrated in the docs http://php.net/manual/en/function.fgets.php and get each line.
Then you can grab the value you want something like this.
$handle = @fopen("test.csv", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
/* this gives you the value */
echo explode(',',$buffer)[0];
}
fclose($handle);
}
Which gives you the data you want
a
1
4
You would need to improve this to deal with real messy data and skip headers etc before you then inserted each number.
Another approach would be loading the csv directly into the database table https://dev.mysql.com/doc/refman/5.1/en/load-data.html