2011-11-18 3 views
0

함수마다 실제로 다른 함수 매개 변수로 함수를 루프하려고합니다.PHP isset 인 경우 자체 함수를 호출하여 사용자 함수를 호출하십시오.

Im 양식에서 제출 한 변수 매개 변수로 $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); 
} 

입니까?

+0

[샘플 코드] (http://sscce.org/)는 완전하고 간결해야하며 문제를 설명하고 자체적으로 서술 할 수있을만큼 충분해야합니다. 관계없는 코드는 혼란 스럽습니다. 이전의 mysql 확장은 구식이며 지원이 중단 될 예정입니다. 새로운 코드는 PDO 나 mysqli 확장을 사용해야하며 둘 다 준비된 문장을 지원한다. 준비된 문 매개 변수는 주입에 취약하지 않습니다. 준비된 문 자체는 반복적 인 쿼리를 사용하는 경우 더 효과적입니다. 문을 한 번만 구문 분석하면되기 때문입니다. – outis

답변

0

당신이하고있는 일을 이해하지 못하기 때문에 내가 알지 못하는 뭔가 다른 것을하려고 시도 할 수도 있지만, 필요한 것이 있다면 재귀 함수이 방법은 아닙니다. 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? 

    } 

    ?> 

그나마 당신이 * 전역의 $ login_name은이 이유를 알고 테스트되지 않은 상태입니다. 함수가 무언가를 반환하거나 데이터베이스에 UPDATE을 수행하도록 하시겠습니까?

+0

나는 (! isset ($ end))을 사용하지 않고, 더 이상 함수를 호출하지 않는다. 그러므로 나는 그 줄이 필요 없다 : $ end = 1; –

+0

도와 줘서 고마워! 나는 몇 가지 기본 사항을 놓치고 있었다 :) 이것은 완벽한 대답이다. U 날을 구 했어요. Btw, 당신을 투표하는 방법을 찾을 수 없습니다 (req 15 평판). – tintinboss

+0

그래도 더 이상 글로벌 플래그가 필요하지 않습니다. $ login_name 변수를 전역 적으로 업데이트하려고했습니다. - 총 잘못된 접근. – tintinboss

관련 문제