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

时间:2013-06-11 23:57:58

标签: php function scope

我觉得这是一个愚蠢的问题,但我无法弄明白。

我有一个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。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

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

另请注意,mysql_*函数have been deprecated as of PHP 5.5。您应该使用MySQLi或PDO。