dtv55860 2017-09-20 11:39
浏览 22
已采纳

while循环到Array转换

Having an issue with a piece of code when trying to pull an array out of a while loop. The code is as follows

$query = "SELECT ID,Assigned_user FROM work_orders";

$result = mysqli_query($connection, $query);

while ($row = mysqli_fetch_assoc($result)) {

    $Assigned[] = $row['Assigned_user'];
    $ID[] = $row['ID'];

    var_dump($ID);

The issue is when var_dump() returns its results the $ID[] is split in to two arrays which look like the following

array (size=1)
  0 => string '2' (length=1)
D:\wamp64\www\MYCMS\Admin\test.php:31:
array (size=2)
  0 => string '2' (length=1)
  1 => string '3' (length=1)

Where i need it to be one array which consists of the two values like Array ( [0] => 2 [1] => 3 )

then i need to explode it like

$IDS = explode(",", $ID);

so it becomes a string "2,3" so it can be used in the IN statement

to insert in to a select statement from my database

$wo_request = "SELECT * from work_orders Where ID IN ('$ID')";

if anyone can guide me on how to do this i would really appreciate it.

P.S I cant str_split it either since this needs to work for a whole load of numbers that go in to the hundreds so split it down to one character doesn't work `

  • 写回答

4条回答 默认 最新

  • dor2p0520 2017-09-20 11:41
    关注

    It is because you have dumped array inside while loop. var_dump after while loop then check

    while ($row = mysqli_fetch_assoc($result)) {
    
        $Assigned[] = $row['Assigned_user'];
        $ID[] = $row['ID'];
    } //complete while loop
    
        var_dump($ID);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件