Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6764343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:34:58+00:00 2026-05-26T14:34:58+00:00

the data is stored in the database as the image shows. the table is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:34:59+00:00Added an answer on May 26, 2026 at 2:34 pm
    • Open the file test.txt
    • Read it line by line
    • For each line read; split it on whitespace to get the product’s model
      and price.
    • If the price part is empty make it 0
    • Now use these values in the update query.

    Translated to PHP code (without error checking):

    $file = fopen("test.txt","r");
    while($line = fgets($file)) {
      $line = trim($line);
      list($model,$price) = preg_split('/\s+/',$line);
      if(empty($price)) {
        $price = 0;
      }
      $sql = "UPDATE products
              SET products_price=$price
              WHERE products_model='$model'";    
      // run the sql query.
    }
    fclose($file);
    

    Also you’ll have to skip the first record.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got hierarchal data in the database, stored in Modified Preorder Tree Traversal format.
In my database I have stored images in the image data type, showing up
I have the following scenario: I have various user's data stored in my database.
I have a database which contains picture data stored as a binary blob. The
If the amount of data stored within a given field of a database is
I have data stored as below in an MS Access database: Date User 20090101
I am designing an app in which the data is stored in the database.
I am working on a (database-ish) project, where data is stored in a flat
In asp.net(C#) i want to fetch data from a database using a stored procedure
I am using Microsoft Access database for storing data. In that, I stored date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.