I’m trying to actually loop a function with a different function parameter each time which is obtained by the function itself;
Im using a variable $login_name as function parameter which was submitted by a form. So I want to change this parameter by the function itself. absurd? is there any alternative?
Here’s my function
$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);
}
Where is the problem?
I dont understand what you ar doing, so you might be trying to do something different that I do not know about, but if what you need is an recursive function then this is not the way. You dont define the function inside a while-loop, the function should be defined as a normal function, but in can call itself whit a different result.
This is how your function would be as recursive.
This is not tested code
Dont know why you have *global $login_name;* at the end. Do you want the function to return something or just perform the UPDATE in the database?