简体   繁体   中英

How to insert array value into single column and single row in php

I want to insert array value into database single row and column

$str_accommodation_level = "SELECT * FROM interest";
$query_accommodation_level = $dbcon->query($str_accommodation_level);
while ($accommodation_level = $query_accommodation_level->fetch_array()) {
    $level_from = 'type' . $accommodation_level['id'];
    if (isset($_COOKIE[$level_from])) {
        $level_data += '<span>' . $_COOKIE[$level_from] . '</span> <br>';
    }
    print $level_data;
}

use php implode . The implode() function returns a string from the elements of an array .

$arr = array('1','2','3','4');
$str=implode(",",$arr);

or insert like that :-

INSERT INTO table_name (column1)
VALUES ('$str')

Here I am selecting multiple files form dropdown, I am storing those in array then updating into database.Here filename is name of select tag.

 @$filename= $_POST['filename'];
    $title = implode(',',@$filename);
    $sql .="INSERT INTO createtest_filename(id,filename) VALUES('".$max_id."','".$title."');";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM