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 4020582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:14:46+00:00 2026-05-20T10:14:46+00:00

hi so this is the setup: i need to update some prices from a

  • 0

hi
so this is the setup: i need to update some prices from a csv file called pricelist.csv. the database table is called products and there is a column called product_id, which contains the product ids which can also be found in the first column of the csv file and the prices and lastly i need are located in the 7th column of the csv file. i need to write these to the price column of my database.
i have tried my best to come up with the code, but it just seems too much for my skill level. here is what i made:

<?php  
include("admin/include/db.php");  
$res=mysql_query("select * from products");  
$row = 1;  
$mycsvfile = array(); //define the main array.  
if (($handle = fopen("pricelist.csv", "r")) !== FALSE) {  
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
    {  
        $num = count($data);  
        $row++;  
        $mycsvfile[] = $data;  
    }  
    fclose($handle);  
}  

$row['product_id'] = $mycsvfile[$which_row][1] //trying to find the row in the csv  
$mycsvfile[$which_row][7] = $price; //should get price, but previous line does not work   

while($row=mysql_fetch_array($res))  
{  
    mysql_query("update products set price='".$price."', isavailable='1' where id='".$row['id']."'");  
}  
?>

any sort of help is welcome! thanks

  • 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-20T10:14:47+00:00Added an answer on May 20, 2026 at 10:14 am

    I think you are looking for this (but I didn’t test it):

    <?php
    include("admin/include/db.php");
    
    if( ( $handle = fopen("pricelist.csv", "r") ) !== FALSE )
    {
        while( ( $r = fgetcsv( $handle, 1000, ";") ) !== FALSE )
        {
            mysql_query('UPDATE products SET "price"="'.$r[6].'", "isavailable"="1" where "id"="'.$r[0].'"');  
        }
    }
    

    Disclaimer: Yes I know I didn’t sanitize the data, but I don’t feel like working with outdated mysql functions.

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

Sidebar

Related Questions

I need to set up this scenario: A SQL Server 2005 database will create
I have a data tables with this type of setup. Table A AID AName
I'm implementing a table with a fixed header using this kind of setup: <div
I have this setup where in my development copy I can commit changes on
I have a setup project for my C# program, and this setup project has
I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
The offending command that msi executes is: .\devenv.com /command View.Toolbox /setup This fails with
I have a ToggleButtonBar with a DataProvider setup like this: <mx:ToggleButtonBar itemClick=clickHandler(event); selectedIndex=0> <mx:dataProvider>
This will require a little setup. Trust me that this is for a good
Our VSS setup is like this: We have a set of unique folders with

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.