Support

  1. tpelek
  2. General
  3. Tuesday, February 20 2018, 09:16 PM
Hello I have filed that I want to update using PHP script using $query->update, the field type is select with Multiple selection ON.
In database I see the data is like this ["0","1","3"]
I made some tries but it’s not possible to add or remove just one value
For example, I can replace ["0","1","3"] with ["2"] but I cannot add the 2 in exist values and be ["0","1","2","3"]
There any way to add or remove a single value?
Thanks
Accepted Answer
admin Accepted Answer
Admin
Hi,
yes, this is a JSON format, so you use a PHP script like:
$raw_value = '["0","1","3"]';
$array_value = json_decode($raw_value);
if(!is_array($array_value)) $array_value = array();

// Add Value
$value_to_add = '2';
if(!in_array($value_to_add, $array_value)) // if is not already available in array
array_push($array_value,$value_to_add);

// Remove Value
$value_to_remove = '0';
if(in_array($value_to_remove, $array_value)) // if value to remove is available in array
$array_value=array_diff($array_value, array($value_to_remove));

$new_raw_value = json_encode($array_value);
  1. more than a month ago
  2. General
  3. # Permalink
tpelek Accepted Answer
Pro
Content Protected
  1. more than a month ago
  2. General
  3. # 1
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy Profile® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.