-1

I have table item like this:

id       color           stock
1     red,green,yellow   10,20,30

and i grab an item with red color 5 and green 2 and put on table x like this :

id   id_product    color    qty
1       1           red      5   
1       1           green    2  

what i want to achieve is to update table item become like this :

id       color           stock
1     red,green,yellow   5,18,30

what i do is :

$colors = $resultset['color'];
$color = explode(",",$result['color']);
$stock = explode(",",$result['stock']);
$flag = array_search($colors,$color);
$stock[$flag] = $stock[$flag] - $resultset['qty'];

from a code that i write above, when i echo $stock[$flag] it will return 5 and 18, but how can i implode that to become 5,18,30?

My problem is, i have 2 item in table x that have a same id_product but difference color, so when i do some looping and i do implode it give a result like this : 5,20,30 10,18,30. So, when i update to the table item, it just change like this :

id       color           stock
1     red,green,yellow   10,18,30

I just need some suggestion or help to figure out how can i implode that stock to become : 5,18,30. I will appreciate for the answer and suggestion..thx

fenz kurol
  • 113
  • 1
  • 10

1 Answers1

0

It seems you are asking for, which is probably not the case given that you can use explode and want to implode so you would know the function, but just in case:

implode(",", $stock);

Jack M.
  • 1,195
  • 13
  • 30
  • i already try that, but i have 2 item in my table x, so when i do looping, it give result like this : 5,20,30 10,18,30.. That's a reason why i asking in here – fenz kurol Mar 21 '13 at 19:07
  • I dont understand then. You should post your whole actual code, it sounds like something is wrong with your logic. Also, keeping inventory in tables like that is sketchy, you should have 1 line per item. – Jack M. Mar 21 '13 at 19:11