Jump to content

[SOLVED] append or create data in mysql cell mysql OR php


ratcateme

Recommended Posts

i have this code to add an id number to a list of id  numbers

"UPDATE `people` SET `siblings` = CONCAT(`siblings` ,'|{$id}') {$where};"

so if you have a cell  like this

30|15|16|20

run that code with an id of 50 you will get

30|15|16|20|50

but if the cell is emtpy you get

|50

so when i use explode('|',$ids) i will get a array with one empty and one id

but i want to get a array with just the one id.

can anyone help me with a solution using minimal extra PHP and MySQL code.

 

Scott.

I am not really understanding your problem really. But it seems like you want to remove empty items from an array, if so look into the array_filter function. This function will remove empty items from an array

UPDATE abc SET siblings = IF(siblings ='', '$id', CONCAT(siblings, '|', '$id'))

 

However, IMO, the design is bad.

 

Better to normalise your data and have a siblings table with each sibling in a separate row. EG

[pre]

id    peopleID      siblingID 

-----  ---------    -----------

1        1            30   

2        1            15   

3        1            16   

4        1            20

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.