Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Import pricelist to keep prices up to date


NL_Remi_NL

Recommended Posts

What I want to achieve is this:

1. auto download pricelist (done using wget / unzip)

2. import excel sheet into mysql (done using excel2mysql perl script)

3. update the prices in the products database, and send an e-mail with the remaining records (new articles, should be inserted in the database)

 

The first two steps run flawlessly, but then it stops. I wrote a command-line php script which doesn't do what it should. Am I doing something impossible? Am I doing it wrong? Is there an easier way?

 

Here is the php code with comments:

 

<?PHP
$cn = mysql_connect("localhost", "username", "password")or die ("connection failed"); //connecting to the db
@mysql_select_db("realonecomp_nl",$cn) or die ("No such database"); //select the right database
$sql_tempsmall = mysql_query("SELECT * FROM tempsmall ORDER BY ART_NO",$cn)or die (mysql_error());//get all records in a recordset
while ($rs_tempsmall = mysql_fetch_row($sql_tempsmall) or die (mysql_error())) { // for each record
       $temp_id=$rs_tempsmall[0]; //get the ART_NO value into a string
       $sql_oscread = mysql_query("SELECT * FROM products WHERE products_model='$temp_id'",$cn)or die(mysql_error()); // select the row which matches the ART_NO string
       $count_oscread = mysql_num_rows($sql_oscread) or die (mysql_error()); //check if there is a record returned
       if ($count_oscread>=1) { // there is an record which matches. Update the price
               mysql_query("UPDATE products SET products_price='$rs_tempsmall[ART_PRICE]' where products_id='$rs_tempsmall[ART_ID]'",$cn) or die (mysql_error());
               } else {
               print "new product"; //else print a debug message
               $new_prod = "yes";
       }
}
if ($new_prod == "yes") {
       echo "Er is 1 nieuw product gevonden."; // another debug message, here comes the code for the mailing later on.
}
mysql_close();
?>

 

I must note that i'm kinda new to PHP and MySQL, but i do have a lot of experience with ASP and MS-SQL. (We're moving to new servers, that's why i need to switch to php)

Link to comment
Share on other sites

Will that import my excel sheet? And is it possible to start it from the command-line so it can be set as an crontab? My prices change at least daily, and I have over 6000 products. You can imagine it isn't possible to keep them all up to date by hand.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...