您好,我仍然在尝试更改为mysqli,而且我有时可以使事情顺利进行。
我最大的东西是mysqli_result,我尝试了别人做的事情,似乎没有用。
这是下面的代码:

$result = mysqli_query($con, "SELECT referer FROM users WHERE userId = '$key'");
if(mysql_result($result, 0) != "" ){
    $referer = mysql_result($result, 0);
    $result = mysqli_query($con, "SELECT referer FROM users WHERE userId = $referer'");
    if(mysql_result($result, 0) != "" ){
        $result2 = mysqli_query($con, "SELECT refered FROM users WHERE userId = $referer'");
        $newRefs = mysql_result($result2, 0) + 1;
        mysqli_query($con, "UPDATE users SET refered = '$newRefs' WHERE userId = '$referer'");
        $result3 = mysqli_query($con, "SELECT userName FROM users WHERE userId = '$key'");
        $refered = mysql_result($result3, 0);
    }
}


帮助将不胜感激。

亲切的问候
乍得

最佳答案

您不能像这样混用mysql_mysqli_函数。另外,mysql_result是一门严肃的老学校。 mysqli中没有等效项(这是一件好事)。我切换到mysqli_fetch_assoc,它将接受您的查询并返回一个以字段名称作为键的关联数组。为了统一起见,我将所有过程都保留了下来(我讨厌将OOP与过程混合使用)。我应该注意,您的代码在编写时令人费解(例如,$key并未在任何地方定义)。最好避免重用像您一样拥有的变量。我也强烈建议切换到全对象代码库。

$result = mysqli_query($con, "SELECT referer FROM users WHERE userId = '$key'");
if($row = mysqli_fetch_assoc($result)){
    $result2 = mysqli_query($con, "SELECT referer FROM users WHERE userId = '" . $row['referer'] . "'");
    if($row2 = mysqli_fetch_assoc($result2)){
        $result3 = mysqli_query($con, "SELECT refered FROM users WHERE userId = '" . $row2['referer'] . "'");
        $newRefs = mysqli_fetch_assoc($result3);
        mysqli_query($con, "UPDATE users SET refered = '" . $newRefs['refered'] . "' WHERE userId = '" . $row['referer'] . "'");
        $result4 = mysqli_query($con, "SELECT userName FROM users WHERE userId = '$key'");
        $refered = mysqli_fetch_assoc($result4);
    }
}

07-26 09:29