gpt4 book ai didi

mysql - Laravel DB 查询数组

转载 作者:行者123 更新时间:2023-11-30 21:46:17 24 4
gpt4 key购买 nike

我将“hello,world”作为数组存储在 mysql 数据库中,然后尝试使用以下查询进行检索

 @php
$post_id = $post->id;
$result= DB::table('posts')
->select('tags')
->where('id', '=', $post_id)
->get();

echo($result);

@endphp

回显结果为:

[{"tags":"hello,world"}] 

我需要为上面的结果回显单个值

hello 

world

最佳答案

@php
$post_id = $post->id;
$result= DB::table('posts')
->select('tags')
->where('id', '=', $post_id)
->first();

$tags = $results->tags;
$tagsArray = explode(',', $tags);
@endphp

现在

@foreach($tagsArray as $ta)
{{ $ta }} <br />

@endforeach

你的输出将是

hello

world

关于mysql - Laravel DB 查询数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49318034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com