PHP Вызов пользовательской функции со своим собственным результатом, если isset - PullRequest
0 голосов
/ 18 ноября 2011

Я пытаюсь фактически зациклить функцию с другим параметром функции каждый раз, который получается самой функцией;

Я использую переменную $login_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);
}

В чем проблема?

1 Ответ

0 голосов
/ 18 ноября 2011

Я не понимаю, что вы делаете, поэтому вы можете пытаться сделать что-то другое, о чем я не знаю, но если вам нужна рекурсивная функция , то это не тот путь.Вы не определяете функцию внутри цикла while, функция должна быть определена как обычная функция, но она может вызывать сама себя с другим результатом.

Так ваша функция будет выглядеть как рекурсивная. Это не проверенный код

    <?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?

    }

    ?>

Не знаю, почему у вас есть * global $ login_name; * в конце.Вы хотите, чтобы функция возвращала что-то или просто выполняла ОБНОВЛЕНИЕ в базе данных?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...