making an array from database [closed]

﹥>﹥吖頭↗ 提交于 2019-12-04 06:54:23

问题


I'm going crazy with this issue, I want to get an array separated by commas(string) like example:(1,2,4,6) from a database and insert this as a variable inside a query like(select from table where id IN($variable string). Can anyone help me with this?

example:

<?php
//connect
$sql = "select id from users where id=1";
//get the results as an array

insert that variable inside this query

select from table where id IN($variable);
//
?>

i tried multiple ways and always have different issues. Please need an answer!


回答1:


implode()transforms an array into a string of values separated by the char you choose:

$arr = array(1,2,3,4,5,6,7,8,9); // make an array
$list = implode(',',$arr);
$sql = "SELECT * FROM table WHERE id IN($list)";


来源:https://stackoverflow.com/questions/16469388/making-an-array-from-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!