简体   繁体   English

PHP从MySQL数据库获取多个数组并序列化数组

[英]php fetch multiple array and serialize array from mysql database

I have this table for insert files data : 我有此表用于插入文件数据:

|id|url|author|post_id|post_type|timestamp|

In url field i insert PHP serialize data and fetch with this function: url字段中,我插入PHP serialize数据并使用以下函数进行获取:

function _is_files_list_($id,$type){

$files = mysqli::fetch("SELECT * FROM " . NEWS_FILES . " WHERE news_id = ? AND type = ? ",$id , $type ); 

if (count($files) > 0) {

    $list_files = unserialize($files[0]['url']);
        $count  =   count($list_files[0]);
        for($i=0; $i<$count; $i++){
            $files_show[]  =   array($list_files[0][$i]);
        }
    return $files_show;

    }
else
{
    return FALSE;
}
}

and result : 结果:

if(($list = _is_files_list_($id,"download")) !== false){

    foreach ($list as $key => $data) {
        echo urldecode($data[0]);
    }
}

This worked for me and print/show url field form table but I need to show other table field ie author or timestamp using this function. 这对我来说很有效,并且可以打印/显示url字段表格表格,但是我需要使用此功能显示其他表格字段,即authortimestamp

How can I generate this ? 我如何产生这个?

did you tried something like? 你尝试过类似的东西吗?

foreach ($list as $key => $data) {
    echo $data[key]['url'];
    echo $data[key]['author'];
    echo $data[key]['timestamp '];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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