Msqli查询数组 [英] Msqli query array

查看:92
本文介绍了Msqli查询数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有我的代码

    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'];
        }
}

如果我调用此函数的输出 $ Apicall [0] = 3 $ Apicall [1] = 11 这就是我想要的信息.但是现在我想使用

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;
}

如果我设置$ Apicall ="3",则此代码会运行;我遇到的问题是,我希望第一个函数获取数据库中与$ userId关联的所有ID,然后为每个ID运行第二个函数,以从该查询中获取两个特定的信息.

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.

推荐答案

针对以下评论,这是我要使用的解决方案. 但是,您应该警惕使用此方法,因为它不会参数化值,因此也没有被清除.

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;
}

?>

这篇关于Msqli查询数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆