duanbei1903
2016-07-10 14:16如何从数据库中获取逗号分隔值
I have the following mysqli query, and I want to implode the array that's outputted into a (1,2,3,4)
type format.
Here's the query and the asoc array code:
$user_categories = mysqli_query($connect, "SELECT sub_cat FROM subscriptions WHERE sub_user_id = '$user_id'");
$category_ids = mysqli_fetch_all($user_categories,MYSQLI_NUM);
print_r($category_ids);
$category_ids = implode(", ",$category_ids);
I then get the following output, and I can't seem to isolate the values...
Array (
[0] => Array ( [0] => 5 )
[1] => Array ( [0] => 8 )
[2] => Array ( [0] => 4 )
[3] => Array ( [0] => 2 )
)
Apologies if I'm missing something really obvious here. I've been trying to fix this for a while, and due to my lack of PHP experience, I'm not 100% sure what to search for.
I've also tried a simple implode using the results of the $user_categories
query, following the instructions of other StackExchange answers I've seen on the topic, but got nothing (code below):
$user_categories = mysqli_query($connect, "SELECT sub_cat FROM subscriptions WHERE sub_user_id = '$user_id'");
$category_ids = implode(", ",$user_categories);
echo $category_ids;
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 特别是从mysql数据库中获取逗号分隔值
- sql
- mysql
- php
- 1个回答
- 如何在MySQL中以单行的形式获取以逗号分隔格式存储的图像?
- mysql
- file-upload
- php
- 4个回答
- 如何从数据库中获取逗号分隔值
- mysql
- arrays
- php
- 3个回答
- 读取form里上传的txt文件
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- 如何从 Java 中的字符串值中获取枚举值?
- java
- enums
- guava
- 8个回答
换一换