php - 将一些数据反序列化为数组

我有一个问题,要从存储在一个表中的序列化数据中获取一些数据,然后将其用于排队另一个表。我的方法是下面的方法,但是我对编程很陌生,它不起作用

table wppg_album
id - name -   gallery_list
1 - album1 -  a:1:{i:0;s:1:"1";i:1;s:1:"8"}
2 - album2 -  a:2:{i:0;s:2:"17";i:1;s:2:"19";i:2;s:2:"18";}
3 - album3 -  a:3:{i:0;s:2:"13";}


我一直在获取SQL字符串并在选定的ID的单元格gallery_list中反序列化数据。

现在要修复的相册已修复,告诉#2我必须获取 array(17,18,19)才能最终从Galleries表中获取结果。

我写了这段代码,但无法获取串行数据

<?php 
    $sql = "SELECT * FROM ".WPPG_TBL_ALBUM." WHERE id = 2";
    $result = mysql_query($sql);
    $stringGalleries = mysql_fetch_object($result);
    $galleries = unserialize($stringGalleries);
    $ids = join(',',$galleries); 
    $data = $wpdb->get_results("SELECT * FROM ".WPPG_TBL_GALLERY." WHERE id IN   ($ids)");
?>


任何帮助将不胜感激。

最佳答案

您输入错了$和;失踪

$galleries = unserialize($stringGalleries);


你也用错误的方式使用mysql_fetch_object ...这是正确的代码

<?php 
    $sql = "SELECT * FROM ".WPPG_TBL_ALBUM." WHERE id = 2";
    $result = mysql_query($sql);
    while ($galleriesRow = mysql_fetch_object($result)) {
        $galleries = unserialize($galleriesRow->gallery_list);
        $ids = join(',',$galleries); 
        $data = $wpdb->get_results("SELECT * FROM ".WPPG_TBL_GALLERY." WHERE id IN (" . $ids. ")");
    }
?>