gpt4 book ai didi

php - pgsql查询结果用逗号分隔

转载 作者:行者123 更新时间:2023-11-29 13:13:25 25 4
gpt4 key购买 nike

我的数据库表//名称:帐户

id | login | password | macaddress
1 | ab | ex | 2X:D0:5X:5E:77:CX
2 | ac | example | 2X:D0:5X:5E:77:CX
3 | ad | example | 5X:Y0:GX:FE:27:G8

查询

$sql = pg_query("SELECT * FROM accounts where macaddress = '2X:D0:5X:5E:77:CX' ")
while( $row = pg_fetch_assoc($sql) )
echo "$row[id]";

结果:1​​2

我想要的结果是:1,2

希望你能帮我解决这个问题。谢谢

最佳答案

首先将值放入一个数组中,然后将它们连接起来。

$array = [];

$sql = pg_query("SELECT * FROM accounts where macaddress = '2X:D0:5X:5E:77:CX' ")
while( $row = pg_fetch_assoc($sql) )
$array[] = $row[id];

echo join(',', $array);

关于php - pgsql查询结果用逗号分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51914201/

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