Php 取消序列化数组并从其中输出数据
我从数据库中收到以下信息Php 取消序列化数组并从其中输出数据,php,arrays,wordpress,serialization,Php,Arrays,Wordpress,Serialization,我从数据库中收到以下信息 Array ( [0] => stdClass Object ( [id] => 1 [userid] => 2 [collection_name] => Programm Title [collection_data] => a:2:{i:2;a:7:{s:10:"ExerciseID";s:1:"2";s:11:"Description";s:11:"Des
Array
(
[0] => stdClass Object
(
[id] => 1
[userid] => 2
[collection_name] => Programm Title
[collection_data] => a:2:{i:2;a:7:{s:10:"ExerciseID";s:1:"2";s:11:"Description";s:11:"Description";s:4:"Sets";s:3:"123";s:4:"Reps";s:3:"123";s:4:"Load";s:3:"123";s:4:"Rest";s:3:"123";s:5:"Tempo";s:3:"123";}i:3;a:7:{s:10:"ExerciseID";s:1:"3";s:11:"Description";s:0:"";s:4:"Sets";s:0:"";s:4:"Reps";s:0:"";s:4:"Load";s:0:"";s:4:"Rest";s:0:"";s:5:"Tempo";s:0:"";}}
)`
)
我希望取消序列化集合\u数据
,这将为我提供如下数组:
Array
(
[434] => Array
(
[ExerciseID] => 434
[Description] =>
[Sets] =>
[Reps] =>
[Load] =>
[Rest] =>
[Tempo] =>
)
)
然后,我希望运行以下命令来查询数据库中的练习ID
$ids = array();
if(empty($newdata))
{echo"<p>There is something wrong with that link, please speak to your coach!</p>";}
else
{
foreach($newdata as $el)
{
$ids[] = $el['ExerciseID'];
}
}
// START OF THE QUERY USING THE EXERCISE ID'S FOR DISPLAYING IN THE COLLECTION
$the_query = new WP_Query(array('post__in' => $ids, 'post_type' => 'exercise','posts_per_page' =>'40')); ?>
<?php if ( $the_query->have_posts() && $ids ) : ?>
<!-- the loop to get the psots that are in the array / collection -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- <?php the_post_thumbnail('collection_thumb'); ?> -->
<div class="well">
<?php $exid = get_the_ID(); ?>
<?php
$description = $newdata[$exid]['Description'];
$sets = $newdata[$exid]['Sets'];
$reps = $newdata[$exid]['Reps'];
$rest = $newdata[$exid]['Rest'];
$load = $newdata[$exid]['Load'];
$tempo = $newdata[$exid]['Tempo'];
?>
<h3><?php the_title(); ?></h3>
<?php
$exerciseID = get_the_ID();
$blogUrl = get_site_url();
global $wpdb;
$query = "
SELECT *
FROM imagemap
WHERE exercise = '".$exerciseID."'";
$result = $wpdb->get_results($query);
foreach($result as $row)
{
echo '<div class="imageGridImages">';
// echo "<img src=".$blogUrl. "/image/thumb/".$row->id. ".jpg />";
echo '<div class="image display" style="background-image: url(' .$blogUrl.'/image/thumb/' .$row->id. '.jpg);"></div>';
echo '</div>';
}
// echo $row->id." ".$row->exercise." ".$row->source." <br>";
// echo $query;
// var_dump($result)
?>
$ids=array();
if(空($newdata))
{echo“该链接有问题,请与您的教练联系!”;}
其他的
{
foreach($newdata作为$el)
{
$ids[]=$el['ExerciseID'];
}
}
//使用用于在集合中显示的练习ID开始查询
$the_query=new WP_query(数组('post_in'=>$id,'post_type'=>'exercise','posts_per_page'=>'40'));?>
我能够通过以下方式访问阵列中的序列化数据:
$result[0]->collection_data
您可以提取数据
$unserialize = unserialize ($result[0]->collection_data);
var_dump($unserialize);