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 setup ActiveMQ with MySQL which i follow this article http://note19.com/2007/06/23/configure-activemq-with-mysql/ I
I need help with one ajax function This is raw page setup. Page will
This is a kind of a random thing I need. Basically my setup is
Is there any drawback to this setup? I want to be able to run
I have this following setup, a textarea named with some data in it that
I need to create some way to get a local WAR file deployed on
First, here are some scripts to setup the tables and background. CREATE TABLE TEST_P
I'm trying to setup a demo of some software for a client and need
I have this setup in my models: class Author(models.Model): name = models.CharField(max_length=100) class Topic(models.Model):
On my portfolio page I have this setup: <div id=portfolio> <ul id=sites> <li> <h3><a

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.