Project Detail

$10 just to fill in whats wrong on this script  

$10 just to fill in whats wrong on this script is project number 316081
posted at Freelancer.com. Click here to post your own project.

 

| More Free Trial For New Buyers
 

Status:

Selected Providers: dboyzhang

Budget: $30-250

Created: 09/17/2008 at 2:26 EDT

Bid Count: 2

Average Bid:
$ 40

09/18/2008 at 2:26 EDT

Project Creator: jaxdevil
Employer Rating: 10/1010/1010/1010/1010/1010/1010/1010/1010/1010/10 (28 reviews)

Bid On This Project
 

Description

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,AT-Express.jpg,AT-Express.pdf,,,,,85,"75226 [Dallas, TX]",35,13.25,15.05,17.19,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 ('./products.csv');

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);


Messages Posted:0 View project clarification board Post message on project clarification board

Bid On This Project
 

If you are the project creator or one of the bidders Log In for more options

 

30

0 days

09-17-2008 02:51 EDT

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

help

 

50

4 days

09-17-2008 03:02 EDT

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

help


    Bid on this Project