Sedang Disiapkan

$10 just to fill in whats wrong on this script

Remember, all I need is the info on this, so I am only offering $10 for this one, just take a look, and if you know what I need to change to make it work I will pay you $10:

I have a script for uploading csv files into my MySQL Database tables. The problem is it loads one file into one table, what I need it to do is to mark the columns based on the column name and upload each column to the right table. The 4 tables and the columns they contained I listed below:

products

"categories","manufacturer","model_number","name","list_price"

products_description

"manufacturer","model_number","description"

products_media

"manufacturer","model_number","image_file","pdf_specs","pdf_one","pdf_two","pdf_three","pdf_four"

products_ship

"manufacturer","model_number","freight_class","ship_from","weight","height","width","depth"

And here is a copy of the contents of a one line csv file that would be uploaded, just as an example, in normal effect it will be hundreds of lines, but this is just a single line to show what I mean:

Code:

categories,manufacturer,model_number,name,description,image_file,pdf_specs,pdf_one,pdf_two,pdf_three,pdf_four,freight_class,ship_from,weight,height,width,depth,list_price

Cooking|Toasters_and_Toaster_Ovens,APW Wyott,AT-Express,AT Express Radiant Conveyor Toasters,ELECTRIC : 120V 1725W 14.4 Amps 60hz DIMENSIONS : 13 1/4inH x 15 3/64inW x 17 3/16inD LBS : 35,[url removed, login to view],[url removed, login to view],,,,,85,"75226 [Dallas, TX]",35,[url removed, login to view],[url removed, login to view],[url removed, login to view],1144

So the base code I use for uploading one file to one database is below, I need to make it work for uploading data from one csv file into separate tables based on the column name.

Code:

$fcontents = file ('./[url removed, login to view]');

for($i=0; $i<sizeof($fcontents); $i++) {

$line = trim($fcontents[$i]);

$arr = explode(",", $line);

$sql = "insert into `products` values ('".

implode("','", $arr) ."')";

mysql_query($sql);

echo $sql ."<br>n";

if(mysql_error()) {

echo mysql_error() ."<br>n";

}

}

Any ideas?

I came up with the following code, but it needs to break the $values up into the right array sets for each sql insert query:

Code:

$table_products = "`categories` , `manufacturer`, `model_number`, `list_price` ";

$table_products_description = "`manufacturer` , `model_number`, `description` ";

$table_products_media = "`manufacturer`, `model_number`, `image_file`, `pdf_specs`, `pdf_one`, `pdf_two`, `pdf_three`, `pdf_four` ";

$table_products_ship = "`manufacturer`, `model_number`, `freight_class`, `ship_from`, `weight`, `height`, `width`, `depth` ";

$handle = fopen("product_update.csv", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

foreach( $data as $v ) {

$insertValues="'".addslashes(trim($v))."'";

}

$values=inplode(',',$insertValues);

$sql = "INSERT INTO `products` ( $table_products ) VALUES ( $values )";

mysql_query($sql) or die('SQL ERROR:'.mysql_error());

$sql = "INSERT INTO `products_description` ( $table_products_description ) VALUES ( $values )";

mysql_query($sql) or die('SQL ERROR:'.mysql_error());

$sql = "INSERT INTO `products_media` ( $table_products_media ) VALUES ( $values )";

mysql_query($sql) or die('SQL ERROR:'.mysql_error());

$sql = "INSERT INTO `products_ship` ( $table_products_ship ) VALUES ( $values )";

mysql_query($sql) or die('SQL ERROR:'.mysql_error());

}

fclose($handle);

Kemahiran: PHP

Lihat lebih lanjut: upload mean, sql pdf files, sql code pdf, products offering, problem categories, php dallas, line problem, foreach php mysql, data dimensions, dallas php, at just, linux script probleme, sql r, r sql, whats up, v look, trim, single line, lbs, just, just pdf, from fill, fill pdf, fill data, die line

Tentang Majikan:
( 28 ulasan ) Miami, United States

ID Projek: #316081

Dianugerahkan kepada:

dboyzhang

There are two errors in the script, I will send you the modification soon.

$30 USD dalam 0 hari
(282 Ulasan)
7.1

2 pekerja bebas membida secara purata $40 untuk pekerjaan ini

twacoin

hello we are the largest developer of india to create websites and develpoment we have decicated team to hadle these type of project

$50 USD dalam 4 hari
(15 Ulasan)
4.5