试图调用函数PHP中的两个函数


Trying to call two functions within function PHP

我觉得这是一个愚蠢的问题,但是我想不出来。

我有一个php文件,需要ping数据库的时间最少。我有两个函数使用来自ping的相同数据,我试图在一个函数中调用这些函数。

每个函数遍历mysql查询结果并检查不同的条件,如果满足条件则调用另一个函数。问题是,一旦第一个函数执行完毕,第二个函数就不会执行了。

请帮助。

function gather_info(){
$cash_request = check_user_cash_on_hand();
if($cash_request != false){
    check_for_overpay($cash_request);
    check_for_sabotage($cash_request);
}
}

function check_for_overpay($cash_requests){
if(mysql_num_rows($cash_requests) > 0){
    $days_possible_amount = get_days_ads_amount();
    if($days_possible_amount != false){
        $first_bucket = 1/3 * $days_possible_amount;
        $second_bucket = 2/3 * $days_possible_amount;
        while($row = mysql_fetch_assoc($cash_requests)){
            $cash_id = $row["cash_id"];
            $cash_request = $row["CASH"];

            if($cash_request <= $first_bucket){
                echo "I'm in one";

            }else if($cash_request > $first_bucket && $cash_request <= $second_bucket){
                echo "I'm in two";
            }else if($cash_request > $second_bucket){
                notify_admin_of_suspicious_amount($row, "not_possible");
            }
        }
    }   
}   
}

/* CHECKS IF SUM OF CASH REQUESTS PER USER GREATER THAN 5 and LESS THAN OR EQUAL TO HIS EARNED AMOUNT */
function check_for_sabotage($cash_request){
if(mysql_num_rows($cash_request) > 0){
    while($row = mysql_fetch_array($cash_request)){
        $requested_cash = $row["CASH"];
        $available_cash = $row["cash_amount"];
        if($requested_cash > 5 && $requested_cash <= $available_cash){
            echo "you got me";
        }else{
            notify_admin_of_suspicious_amount($row, "not_enough");
        }
    }
}   
}
function notify_admin_of_suspicious_amount($row, $type){
echo "suspicious";

}

基本上,如果check_for_overpay完成,脚本停止,check_for_sabotage永远不会被调用。有什么建议吗?

在函数check_for_overpay()中调用mysql_num_rows()。它需要的连接,mysql_connect(),可能在函数的变量作用域之外,因为它没有被传递,并且在该函数中没有调用创建连接的函数。

还请注意,mysql_*函数在PHP 5.5中已被弃用。你应该使用MySQLi或PDO