0

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

我有一个 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 永远不会被调用。有什么建议么?

4

1 回答 1

0

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

另请注意,从 PHP 5.5 开始,mysql_*函数已被弃用。您应该使用 MySQLi 或 PDO。

于 2013-06-12T00:27:05.710 回答