dongmubi4444 2016-03-04 01:14
浏览 45

Mysqli查询数组

So I have my code

    function GetApi($connection,$UserId){
        global $Apicall;
        $Apicall = array();
        $Apiidquery = mysqli_query($connection, "SELECT ID FROM ` Characterapi`  WHERE UserId = '$UserId'");
        while($results = mysqli_fetch_assoc($Apiidquery)){
            $Apicall[] = $results['ID'];
        }
}

The output of this function if I call $Apicall[0] = 3 $Apicall[1] = 11 and this is the information I want. But now I want to use a function like

  function Keyquery($Apicall,$connection ){
    global $keyidcall, $keyid ,$Vcode;
    $Keyidquery = array();
    $Keyidquery = mysqli_query($connection, "SELECT keyid, Vcode FROM `Characterapi` WHERE ID = '$Apicall'");
    $results = mysqli_fetch_object($Keyidquery);
    $keyid = $results->keyid;
    $Vcode = $results->Vcode;
}

This code does run if i set $Apicall ="3"; The issue im having is that I want the first function to get All the IDs associated with $userId in my data base then for each Id run the second function to to get the two specific pieces of information from that query.

  • 写回答

1条回答 默认 最新

  • douyan1972 2016-03-04 10:59
    关注

    In response to the comment below, this is the solution which I would use. However you should be wary of using this method as it does not parameterize the values, and as such not sanitized.

    <?php
    
      function Keyquery($Apicall,$connection ){
        global $keyidcall, $keyid ,$Vcode;
    
        $string = "ID IN('";
        $string.= implode("','", $Apicall);
        $string.="')";
    
        $Keyidquery = mysqli_query($connection, "SELECT keyid, Vcode FROM `Characterapi` WHERE ".$string.";");
        $results = mysqli_fetch_object($Keyidquery);
        $keyid = $results->keyid;
        $Vcode = $results->Vcode;
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)