ratcateme Posted June 1, 2008 Share Posted June 1, 2008 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 https://forums.phpfreaks.com/topic/108220-solved-append-or-create-data-in-mysql-cell-mysql-or-php/ Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108220-solved-append-or-create-data-in-mysql-cell-mysql-or-php/#findComment-554717 Share on other sites More sharing options...
Barand Posted June 1, 2008 Share Posted June 1, 2008 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 https://forums.phpfreaks.com/topic/108220-solved-append-or-create-data-in-mysql-cell-mysql-or-php/#findComment-554720 Share on other sites More sharing options...
ratcateme Posted June 1, 2008 Author Share Posted June 1, 2008 thanks both of you i think ill go with the sql option. Scott. Link to comment https://forums.phpfreaks.com/topic/108220-solved-append-or-create-data-in-mysql-cell-mysql-or-php/#findComment-554724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.