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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.