Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查行是否存在的MySQLi Num Rows_Php_Mysqli - Fatal编程技术网

Php 检查行是否存在的MySQLi Num Rows

Php 检查行是否存在的MySQLi Num Rows,php,mysqli,Php,Mysqli,因此,使用mysqli_num_行检查ID是否存在。但现在它甚至还没有加载。但它破坏了我的脚本,不确定我遗漏了什么,或者这是不是写错了 任何帮助都将不胜感激。有些时候,需要有新的眼光才能看到一些小错误,我已经一遍又一遍地研究这个问题 $get_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT id from ap_oc where aff_id=$affiliate_id")); if (mysqli_num_rows($get_oc)

因此,使用mysqli_num_行检查ID是否存在。但现在它甚至还没有加载。但它破坏了我的脚本,不确定我遗漏了什么,或者这是不是写错了

任何帮助都将不胜感激。有些时候,需要有新的眼光才能看到一些小错误,我已经一遍又一遍地研究这个问题

$get_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT id from ap_oc where aff_id=$affiliate_id"));

if (mysqli_num_rows($get_oc) > 0) 
{
    $set_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT commission from ap_oc where aff_id=$affiliate_id"));
    $comission = $set_oc['commission'];

    $get_tl_id = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT tl_id from ap_oc where aff_id=$affiliate_id"));
    $teamleaderid = $get_tl_id['tl_id'];

    $get_tl_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT id from ap_oc where aff_id=$teamleaderid"));

        if (mysqli_num_rows($get_tl_oc) > 0) {
            $set_tl_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT commission from ap_oc where aff_id=$teamleaderid"));
            $t2_comission = $set_tl_oc['commission'];
        } 
}

我用这段代码完成了我需要做的事情

   $get_oc = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT id from ap_oc where aff_id=$affiliate_id"));
    $count_oc = $get_oc['id'];
    if($count_oc==''){$count_oc = 0;}
     if ($count_oc > 0) 
        {

对于将来可能有同样问题的人

您应该始终从fetch assoc中拆分
mysqli\u查询
,如果SQL中出现任何故障,您将始终得到一个系统错误,并且无法正确处理。它还将有助于调试代码,因为您可以看到每个阶段都在做什么。