Jump to content

webent

Members
  • Posts

    255
  • Joined

  • Last visited

    Never

About webent

  • Birthday 10/26/1972

Contact Methods

  • Website URL
    http://webwiredenterprises.com
  • Yahoo
    webwired_enterprises

Profile Information

  • Gender
    Male
  • Location
    St. Louis, Missouri, USA

webent's Achievements

Member

Member (2/5)

0

Reputation

  1. Wow, very nice... Thank you so very much sasa!!! It worked like a charm.
  2. Why not use php to pass the variables to javascript instead of trying to output javascript code?
  3. Hi, I have a database that is populated with different vendors products, those vendors provide a link to their product images on their website, which due to high request from my clients, they want those images hosted locally, so I devised a way to do this... Here's my code... function copyFile($image_path,$image,$dirname){ $url = $image_path . $image; @$file = fopen ($url, "rb"); if (!$file) { echo"<font color=red>Failed to copy $url!</font><br>"; return false; }else { $filename = basename($url); $fc = fopen($dirname."$filename", "wb"); while (!feof ($file)) { $line = fread ($file, 1028); fwrite($fc,$line); } fclose($fc); echo "<font color=blue>File $url saved to PC!</font><br>"; mysql_query("UPDATE products SET product_image_path = '' WHERE product_image_path = '$image_path' AND product_image = '$image'"); return true; } } $result = mysql_query("SELECT DISTINCT product_image_path, product_image FROM products WHERE product_image_path != ''"); while ($row = mysql_fetch_assoc($result)) { copyFile($row['product_image_path'], $row['product_image'], "images/"); } It works fine and dandy, but in alot of cases, multiple products will use the same images, possibly even hundreds of times... which causes alot of extra work on the part of this script... So what I thought was that I would have it check to see if that image already exists in the directory in which the images are copied to, prior to running the copyFile function, but that's not working, it just keeps copying the same file over and over and over again. Here's my modified code... $result = mysql_query("SELECT DISTINCT product_image_path, product_image FROM products WHERE product_vendor != 'DropShipDirect' AND product_image_path != ''"); while ($row = mysql_fetch_assoc($result)) { $dir = '/home/webzcart/public_html/resource/images/'; foreach(glob($dir . '*.jpg') as $file){ $filename = basename($file); if ($row['product_image'] != $filename) { copyFile($row['product_image_path'], $row['product_image'], "images/"); } } } Can anyone help me figure out what I'm doing wrong here?
  4. I got it, you know, all this time, and it was LINES TERMINATED BY '\r\n' causing all the problem... Needed to be LINES TERMINATED BY '\n'
  5. The thing is, if you remove this line, IGNORE 1 LINES, it'll at least insert the headers
  6. He said, @var is user variable It works perfectly on his PC via command line... so frustrating
  7. webent

    Searching

    It would help if you would post at minimum your table structure... Also, I'm thinking an "ingredient_to_recipe" table would work nicely, just from what I can understand without seeing the table structure.
  8. According to your sql statement, isn't "employees" the table name?
  9. The programmer came up with this shortly after talking with you... it works on his local machine, showed me snapshots, but it doesn't work on my server... $query = " LOAD DATA LOCAL INFILE '$file' INTO TABLE products FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES ( @var0, @var1, @var2, @var3, @var4, @var5, @var6, @var7, @var8, @var9, @var10, @var11, @var12, @var13, @var14, @var15, @var16, @var17, @var18, @var19, @var20, @var21, @var22 ) SET product_vendor = 'doba', product_sku = @var1, product_quantity = @var17, product_manufacturer = @var5, product_name = @var2, product_line = SUBSTRING_INDEX(@var3, '|', 1), product_master_category = SUBSTRING_INDEX((SUBSTRING_INDEX(@var3, '|', 2)), '|', -1), product_category = SUBSTRING_INDEX(@var3, '|', -1), product_image = SUBSTRING_INDEX(@var4, '/', -1), product_image_path = SUBSTRING(@var4,1,(select LOCATE( (SELECT SUBSTRING_INDEX(@var4, '/', -1)) , @var4))-1), product_description = concat(@var6, '<br />' ,@var7), product_price = @var15, product_msrp = @var16, product_map = IF (@var14>0,'Yes','No'), product_map_price = @var14, product_weight = @var8, product_set_ship_price = @var19, product_added_date = CURRENT_TIMESTAMP, product_upc = @var21, product_metatags_title = concat(@var21, '-' ,@var2), product_metatags_keywords = concat(@var21, '-' ,@var2), product_metatags_description = @var6; ";
  10. Ok, so just put the csv header names in the places that I want that relevant data to go? Wish I would of hired you to do this... The programmer I hired said that it can't be done this way... I'm just wondering how I am going to be able to manipulate some of the fields variables though, if I have to stick it straight into the db?
  11. Yes, but not in the same columnar format as the db table.
  12. fenway, from what I can tell, the csv file has to be in the same format as the table that it's being inserted into... so I devised a plan... check it out... pretty proud of myself... I convert the csv file into a csv file that matches the table and then LOAD DATA LOCAL INFILE ... It works, just everything is in the wrong columns, the commas are throwing it off, but that's just tweaking I'm sure on the conversion part... $new_field = array(); $new_field["product_id"] = ''; $new_field["product_vendor"] = $product_vendor; $new_field["product_model"] = ''; $new_field["product_sku"] = $product_sku; $new_field["product_status"] = ''; $new_field["product_quantity"] = $product_quantity; $new_field["product_manufacturer"] = $product_manufacturer; $new_field["product_name"] = $product_name; $new_field["product_line"] = $product_line; $new_field["product_master_category"] = $product_master_category; $new_field["product_category"] = $product_category; $new_field["product_image"] = $product_image; $new_field["product_image_path"] = $product_image_path; $new_field["product_description"] = $product_description; $new_field["product_price"] = $product_price; $new_field["product_msrp"] = $product_msrp; $new_field["product_map"] = $product_map; $new_field["product_map_price"] = $product_map_price; $new_field["product_weight"] = $product_weight; $new_field["product_height"] = ''; $new_field["product_width"] = ''; $new_field["product_length"] = ''; $new_field["product_set_ship_method"] = ''; $new_field["product_set_ship_price"] = $product_set_ship_price; $new_field["product_quick_ship"] = ''; $new_field["product_added_date"] = $product_added_date; $new_field["product_upc"] = $product_upc; $new_field["product_asin"] = ''; $new_field["product_ebay_cat_id"] = ''; $new_field["product_metatags_title"] = $product_metatags_title; $new_field["product_metatags_keywords"] = $product_metatags_keywords; $new_field["product_metatags_description"] = $product_metatags_description; $fp = fopen('file.csv', 'w'); foreach ($new_field as $line) { fputcsv($fp, split(',', $line)); } fclose($fp); $query = "LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE products FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'"; BTW: WOW, it was fast!
  13. Do you mean like this, $query = "LOAD DATA LOCAL INFILE '$_POST[file_name]' INTO TABLE products (@dummy,$product_vendor,@dummy,$product_sku,@dummy,$product_quantity,$product_manufacturer,$product_name,$product_line,$product_master_category,$product_category,$product_image,$product_image_path,$product_description,$product_price,$product_msrp,$product_map,$product_map_price,$product_weight,@dummy,@dummy,@dummy,@dummy,$product_set_ship_price,@dummy,$product_added_date,$product_upc,@dummy,@dummy,$product_metatags_title,$product_metatags_keywords,$product_metatags_description) FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; If so, that gave the same error... or is that not what you meant either?
  14. You mean like this? $query = "LOAD DATA LOCAL INFILE '$_POST[file_name]' INTO TABLE products (product_id,@dummy,product_vendor,$product_vendor,product_model,@dummy,product_sku,$product_sku,product_status,@dummy,product_quantity,$product_quantity,product_manufacturer,$product_manufacturer,product_name,$product_name,product_line,$product_line,product_master_category,$product_master_category,product_category,$product_category,product_image,$product_image,product_image_path,$product_image_path,product_description,$product_description,product_price,$product_price,product_msrp,$product_msrp,product_map,$product_map,product_map_price,$product_map_price,product_weight,$product_weight,product_height,@dummy,product_width,@dummy,product_length,@dummy,product_set_ship_method,@dummy,product_set_ship_price,$product_set_ship_price,product_quick_ship,@dummy,product_added_date,$product_added_date,product_upc,$product_upc,product_asin,@dummy,product_ebay_cat_id,@dummy,product_metatags_title,$product_metatags_title,product_metatags_keywords,$product_metatags_keywords,product_metatags_description,$product_metatags_description) FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; That gives me this error... Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2669,product_manufacturer,SpaSak,product_name,SpaSak™ 6pc Spa Set,product_' at line 3 Whole query: LOAD DATA LOCAL INFILE 'bed_and_bath_8_21_08.csv' INTO TABLE products (product_id,@dummy,product_vendor,doba,product_model,@dummy,product_sku,GFSPASAK,product_status,@dummy,product_quantity,2669,product_manufacturer,SpaSak,product_name,SpaSak™ 6pc Spa Set,product_line,bed and bath,product_master_category,bath,product_category,bath accessories,product_image,GFSPASAK_800.jpg,product_image_path,http://images.doba.com/products/6/,product_description,Set includes: natural exfoliating loofah, nylon mesh sponge, pumice stone, 3 wooden massagers and storage bag.,product_price,4.15,product_msrp,24.95,product_map,No,product_map_price,0.00,product_weight,0.8000000119,product_height,@dummy,product_width,@dummy,product_length,@dummy,product_set_ship_method,@dummy,product_set_ship_price,8.59,product_quick_ship,@dummy,product_added_date,2008-08-26 10:55:50,product_upc,024409012877,product_asin,@dummy,product_ebay_cat_id,@dummy,product_metatags_title,024409012877 - SpaSak™ 6pc Spa Set,product_metatags_keywords,024409012877 - SpaSak™ 6pc Spa Set,product_metatags_description,Set includes: natural exfoliating loofah, nylon mesh sponge, pumice stone, 3 wooden massagers and storage bag.) FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY ' ' IGNORE 1 LINES
  15. Here's all the different variations that I've tried... /* $query = "LOAD DATA LOCAL INFILE '$_POST[file_name]' INTO TABLE products (@dummy,$product_vendor,@dummy,$product_sku,@dummy,$product_quantity,$product_manufacturer,$product_name,$product_line,$product_master_category,$product_category,$product_image,$product_image_path,$product_description,$product_price,$product_msrp,$product_map,$product_map_price,$product_weight,@dummy,@dummy,@dummy,@dummy,$product_set_ship_price,@dummy,$product_added_date,$product_upc,@dummy,@dummy,$product_metatags_title,$product_metatags_keywords,$product_metatags_description) FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; */ /* $query = "LOAD DATA LOCAL INFILE '$_POST[file_name]' INTO TABLE products (column1,@dummy,column2,$product_vendor,column3,@dummy,column4,$product_sku,column5,@dummy,column6,$product_quantity,column7,$product_manufacturer,column8,$product_name,column9,$product_line,column10,$product_master_category,column11,$product_category,column12,$product_image,column13,$product_image_path,column14,$product_description,column15,$product_price,column16,$product_msrp,column17,$product_map,column18,$product_map_price,column19,$product_weight,column20,@dummy,column21,@dummy,column22,@dummy,column23,@dummy,column24,$product_set_ship_price,column24,@dummy,column25,$product_added_date,column26,$product_upc,column27,@dummy,column28,@dummy,column29,$product_metatags_title,column30,$product_metatags_keywords,column31,$product_metatags_description) FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; */ /* $query = "LOAD DATA INFILE '$_POST[file_name]' INTO TABLE products SET product_vendor = '$product_vendor', product_model = '', product_sku = '$product_sku', product_status = '', product_quantity = '$product_quantity', product_manufacturer = '$product_manufacturer', product_name = '$product_name', product_line = '$product_line', product_master_category = '$product_master_category', product_category = '$product_category', product_image = '$product_image', product_image_path = '$product_image_path', product_description = '$product_description', product_price = '$product_price', product_msrp = '$product_msrp', product_map = '$product_map', product_map_price = '$product_map_price', product_weight = '$product_weight', product_height = '', product_width = '', product_length = '', product_set_ship_method = '', product_set_ship_price = '$product_set_ship_price', product_quick_ship = '', product_added_date = '$product_added_date', product_upc = '$product_upc', product_asin = '', product_ebay_cat_id = '', product_metatags_title = '$product_metatags_title', product_metatags_keywords = '$product_metatags_keywords', product_metatags_description = '$product_metatags_description' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; */ $query = "LOAD DATA LOCAL INFILE '$_POST[file_name]' REPLACE INTO TABLE products SET column1 = '$product_vendor', column2 = '', column3 = '$product_sku', column4 = '', column5 = '$product_quantity', column6 = '$product_manufacturer', column7 = '$product_name', column8 = '$product_line', column9 = '$product_master_category', column10 = '$product_category', column11 = '$product_image', column12 = '$product_image_path', column13 = '$product_description', column14 = '$product_price', column15 = '$product_msrp', column16 = '$product_map', column17 = '$product_map_price', column18 = '$product_weight', column19 = '', column20 = '', column21 = '', column22 = '', column23 = '$product_set_ship_price', column24 = '', column25 = '$product_added_date', column26 = '$product_upc', column27 = '', column28 = '', column29 = '$product_metatags_title', column30 = '$product_metatags_keywords', column31 = '$product_metatags_description' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.