I have an object like this
stdClass Object ([path] => uploads/1482860841920.jpg)
and what I want is to add another value that should be comma separated so i can ADD upto 6 value
Like
stdClass Object ([path] => uploads/1482860841920.jpg, uploads/1233441234.jpg,..)
What I am trying to achieve is update my database field without losing previous upload path and user can keep on adding his uploads path upto 6 values.I didnt find a way to achieve it though mysql so trying with PHP
Its great if I can update this table to
id | path 1 | uploads/1482860841920.jpg
Like
id | path 1 | uploads/1482860841920.jpg , uploads/45828gf1920.jpg , ..
without losing old data
$object = new StdClass;
$object->foo = array("uploads/1482860841920.jpg","uploads/1482860841920.jpg","uploads/1482860841920.jpg");
like this to add values..
There are 2 easy solutions to your problem.
The first one is to concatenate the new path to the other ones :
if(substr_count($object["path"], ",") < 5){
$object["path"].=", ".$newPath;
}
Then, you can insert the variable directly into your database.
The other solution is to use an array :
//initialization
$object["path"] = [];
if(count($object["path"]) < 6){
$object["path"][] = $newPath;
}
And when you want to insert into the database, you implode your array.