Jump to content

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


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%'";

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.