Jump to content

Need to match product with letters before the dash "-"


BillyMako

Recommended Posts

In the product list online i have the same products uner different names due to restrictions on oscommerce.

 

Example:

VDE004-DE

VDE004-DE1

VDE004-DE2

NLD6400-TO

NLD6400-TO1

etc.....

 

In the inventory list it will just have -

VDE004

NLD6400

 

When a product is purchased is decrements one off the stock_level column.

 

I need the code to say decrement 1 off the stock_level where the letters before a dash match the name in the inventory list.

 

So WHERE "VDE004"-DE = VDE004;

 

Can anyone help?

Hello!

 

$product = "VDE004-DE";
//Split the string down, based on our - delimiter
$pieces= explode("-", $product );
// You only want piece 0
echo $pieces[0]; // VDE004

 

http://uk2.php.net/manual/en/function.explode.php

Okay I am assuming that you already have for instance VDE004 in a variable (let's say $id for example), since you're wanting to go from there, matching stuff up, right?

 

$sql = "update tablename set stock_level = stock_level - 1 where product like '$id%'";

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.