Serialized data in mysql database needs to combined in an array

前端 未结 2 453
耶瑟儿~
耶瑟儿~ 2021-01-28 02:02

I am working in PHP/MySQL.

I have a table in my database called hourly in that table their is a column named webaddress these are serialized. There are multiple rows of

2条回答
  •  北海茫月
    2021-01-28 02:09

    EDIT: Now reflects updates based on info by the OP:

    From your question it sounds like each row has one serialized column, and that column contains a serialized array of three items per rows. So this should work:

    $collection = array();
    while ( $row = mysql_fetch_array($results)) {
        $values = unserialize($row[0]);
        # $values has unserialized the data into its own array with 3 items
    
        $collection = array_merge($collection, $values);
    }
    

    If there were three db rows, and each field had a serialized array with three items, $collection now contains an array with 9 items.

提交回复
热议问题