the data is stored in the database as the image shows. the table is products.
https://i.stack.imgur.com/YCQwu.jpg
the text format data, eg:test.txt
products_model products_price
LB2117 19.49
LB2381 25.99
LB2307
LB2380 35.99
LB2468 10.99
LB2139
LB2223 12.99
LB2027 15.99
LB2126 12.99
LB2308 9.99
LB2124 13.99
………..
now, i want to update the products_price with the txt file, products_model is unique, if the products_price in ‘test.txtis empty. using0` to fill.
the php code:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pwd';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('products');
$sql = 'UPDATE products
SET products_price="..."
WHERE products_model=...';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
if update one rows, i know how to do? but how to use the txt or csv file to update the price?
test.txtand price.
0Translated to PHP code (without error checking):
Also you’ll have to skip the first record.