I have this while loop code below written for php, I got no idea why the loop keep repeating endlessly so I put a counter to break it out.
Upon debug the result that echo was, it seems my variable $loop_userid won't overwrite.
Referral is 1021 Referral is 1021 Referral is 1021 Referral is 1021 Referral is 1021 Referral is 1021
I have a list of sql records. for account 1021, the referral was 1000
The Idea of this is
3 Accounts
1008 > 1021 > 1000
But my loop stuck at 1021
I wonder why my $loop_userid won't overwrite with the new value that is drawn out from the database.
From mysql database select
account_id referral
1000
1008 1021
1021 1000
If i echo my sql select statement
select * from account where account_id='1008'
select * from account where account_id='1021'
select * from account where account_id='1021'
select * from account where account_id='1021'
select * from account where account_id='1021'
select * from account where account_id='1021'
Below is my code
$payment_owe_loop = "inside";
//initial userid is my own userid
$loop_userid = $UserId;
//UserId is 1008 at this point
while($payment_owe_loop=="inside")
{
$sql_select = "select * from account where account_id='$loop_userid'";
$result = mysql_query($query);
//echo $sql_select;
$loop_userid = "";
$count = mysql_num_rows($result);
if($count>0)
{
while($rowINNER = mysql_fetch_array($result))
{
$loop_userid = $rowINNER['referral'];
$my_rebate = $rowINNER['rebate'];
$my_cost = (100 - $my_rebate) * $total_cost * 0.01;
}//end while fetch inner row
}//if there rows return
echo " Referral is " . $loop_userid;
if($count==0)
{
$payment_owe_loop = "outside";
}
if($counter>4)
{
$payment_owe_loop = "outside";
}
$counter++;
unset($rowINNER);
}//end while payment loop
Issue solve. I found that I query the wrong sql statement
$sql_select = "select * from account where account_id='$loop_userid'";
$result = mysql_query($query);
It suppose be $sql_select instead of $query
Blinded by the sql statement, I miss out checking the variable that I key in wrongly
while($payment_owe_loop=="inside")that should be a single equal sign. You shouldn't be comparing but assigning which is whatwhiledoes, and not a conditional statement, just as you did forwhile($rowINNER = mysql_fetch_array($result))- You may have meantif()-if($payment_owe_loop=="inside"){...}orwhile($payment_owe_loop ="inside")