这是我的桌子。
Id meta
1 {"stars":["Lucille Ball","Desi Arnaz","Vivian Vance","William Frawley"]}
2 {"stars":["Carol","Tudor Mandia"]}
3 {"stars":["Jony","Vandame"]}
我想得到这个:
Lucille Ball
Desi Arnaz
Vivian Vance
William Frawley
Carol
Tudor Mandia
Jony
Vandame
按顺序。
怎么做?
感谢
答案 0 :(得分:1)
您必须对每个元值进行JSON解码,然后从数组中获取所需的值:
<?php
$query = "SELECT Id, meta FROM table1 ORDER BY Id";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$meta = json_decode($row['meta'], true);
foreach($meta['stars'] as $key=>$value){
echo $value.'<br>';
}
}
?>
输出是:
Lucille Ball
Desi Arnaz
Vivian Vance
William Frawley
Carol
Tudor Mandia
Jony
Vandame