Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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调用一个用户函数,如果设置为_Php_Mysql_Loops - Fatal编程技术网

PHP调用一个用户函数,如果设置为

PHP调用一个用户函数,如果设置为,php,mysql,loops,Php,Mysql,Loops,我试图实际循环一个函数,每次循环一个不同的函数参数,这个参数是由函数本身获得的 Im使用变量$login\u name作为函数参数,该参数由表单提交。所以我想通过函数本身来改变这个参数。荒谬?还有别的选择吗 这是我的函数 $login_name = "U00001"; while (!isset($end)) { function getcount($login_name) { $get_node = mysql_query("SELECT * FROM b_userba

我试图实际循环一个函数,每次循环一个不同的函数参数,这个参数是由函数本身获得的

Im使用变量
$login\u name
作为函数参数,该参数由表单提交。所以我想通过函数本身来改变这个参数。荒谬?还有别的选择吗

这是我的函数

$login_name = "U00001";
while (!isset($end)) {
    function getcount($login_name) {
        $get_node = mysql_query("SELECT * FROM b_userbase WHERE login_name='$login_name'");
        while ($row_node = mysql_fetch_array($get_node)) {
            $node = $row_node["user_node"];
            $placement = $row_node["user_placement"];
        }
        $current_count = mysql_query("SELECT * FROM f_user_matching WHERE u_m_mem='$placement'");
        while ($get_count = mysql_fetch_array($current_count)) {
            $get_left_current = $get_count["u_m_left_current"];
            $get_left_total = $get_count["u_m_left_total"];
            $get_right_current = $get_count["u_m_right_current"];
            $get_right_total = $get_count["u_m_right_total"];
            $update_left_current = $get_left_current + 1;
            $update_right_current = $get_right_current + 1;
            $update_left_total = $get_left_total + 1;
            $update_right_total = $get_right_total + 1;
        }
        if ($node == "L") {
            $increase_qry = mysql_query("UPDATE f_user_matching 
                                            SET u_m_left_current= '{$update_left_current}',
                                                u_m_left_total ='{$update_left_total}'
                                            WHERE u_m_mem ='{$placement}' ");
        }
        if ($node == "R") {
            $increase_qry = mysql_query("UPDATE f_user_matching 
                                            SET u_m_right_current= '{$update_right_current}',
                                                u_m_right_total ='{$update_right_total}'
                                            WHERE u_m_mem ='{$placement}' ");
        }
        $login_name = $placement;
        if ($login_name == "IM000001") {
            $end = 1;
        } else {
            $login_name = $placement;
        }
        global $login_name;
    }
    $count = getcount($login_name);
}

问题出在哪里?

我不明白你在做什么,所以你可能会尝试做一些我不知道的不同的事情,但是如果你需要的是一个递归函数,那么这不是办法。如果不在while循环中定义函数,则该函数应定义为普通函数,但in可以使用不同的结果调用自身

这就是函数递归的方式。 这不是经过测试的代码

    <?php

 $login_name = "U00001";
 $count = getcount($login_name);

 function getcount($login_name) {
        $get_node = mysql_query("SELECT * FROM b_userbase WHERE login_name='$login_name'");
        while ($row_node = mysql_fetch_array($get_node)) {
            $node = $row_node["user_node"];
            $placement = $row_node["user_placement"];
        }
        $current_count = mysql_query("SELECT * FROM f_user_matching WHERE u_m_mem='$placement'");
        while ($get_count = mysql_fetch_array($current_count)) {
            $get_left_current = $get_count["u_m_left_current"];
            $get_left_total = $get_count["u_m_left_total"];
            $get_right_current = $get_count["u_m_right_current"];
            $get_right_total = $get_count["u_m_right_total"];
            $update_left_current = $get_left_current + 1;
            $update_right_current = $get_right_current + 1;
            $update_left_total = $get_left_total + 1;
            $update_right_total = $get_right_total + 1;
        }
        if ($node == "L") {
            $increase_qry = mysql_query("UPDATE f_user_matching 
                                            SET u_m_left_current= '{$update_left_current}',
                                                u_m_left_total ='{$update_left_total}'
                                            WHERE u_m_mem ='{$placement}' ");
        }
        if ($node == "R") {
            $increase_qry = mysql_query("UPDATE f_user_matching 
                                            SET u_m_right_current= '{$update_right_current}',
                                                u_m_right_total ='{$update_right_total}'
                                            WHERE u_m_mem ='{$placement}' ");
        }
        $login_name = $placement;
        if ($login_name != "IM000001") {
            $login_name = $placement;
            $count = getcount($login_name);
        }
        global $login_name; // Dont know why you want this one?

    }

    ?>

我不使用(!isset($end)),我只是不再调用该函数。因此,我不需要行:$end=1;非常感谢你的帮助!我遗漏了一些基本知识:)这很有效,而且是一个完美的答案。你救了我一天。顺便说一句,我找不到办法投票支持你(req 15声誉)。是的,我也不再需要全球旗帜了。只是尝试全局更新$login\u name变量。-完全错误的方法。这太棒了:)在不了解这个过程的情况下发现递归函数的需要表明你在算法方面有天赋:)应该是完整和简洁的——只足以说明问题和独立的立场,但仅此而已。无关的代码会分散注意力。旧的mysql扩展已经过时,正在被弃用。新代码应该使用PDO或mysqli扩展,这两种扩展都支持预先准备好的语句。准备好的语句参数不易被注入。准备好的语句本身在重复查询时性能更好,因为该语句只需要解析一次。