Reputation: 15
I've got an issue related with getting some data from a serialized data stored in a table and to use it for queuing another table. My approach is the following, but I'm quite new to programming and it doesn't work
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";}
I'm stuck with getting SQL string and deserialize data in cell gallery_list for a selected id.
The album to work on is by now fixed, tell #2 i have to get array(17,18,19)
to finally get results from galleries table.
I wrote this code but the getting of the serial data doesen't work
<?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)");
?>
Any help will be appreciated.
Upvotes: 0
Views: 160
Reputation: 5306
you have a typo, $ and ; missing
$galleries = unserialize($stringGalleries);
also you are using mysql_fetch_object in wrong way... here is correct code
<?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. ")");
}
?>
Upvotes: 3