Serialized data in mysql database needs to combined in an array

前端 未结 2 454
耶瑟儿~
耶瑟儿~ 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.

    0 讨论(0)
  • 2021-01-28 02:10

    change it to $test[] = unserialize($row[0]).

    It will unserialize your data into an array, and then push that array into the $test array. To see how it looks, after your loop, add this line:

    print_r($test);
    

    It will be something like this:

    array(
        [0] => array(
            // ... the first record's data
        ),
        [1] => array(
            // ... the second record's data
        ),
        // etc
    )
    
    0 讨论(0)
提交回复
热议问题