php - Query in a while loop fetching stale data -


i trying (and not succeeding) run while loop query gets last row in table, uses data create new row selects last row in table again (which should row created) uses data , creates new row. should repeat until while loop no longer true.

the problem have while loop runs uses row selected first time round. same row inserted on , on until while loop false.

my question how can query refresh when while loop starts new loop?

i have tried unset() did not work , out of ideas. here while loop of code (which still in progress - still add):-

while ($total_debt > 0) {     $get_dp_accounts_list_query = "select account_id         money_debt_planner         customer_id = '".$_session['customer_id']."'         group account_id";     $get_dp_accounts_list = $db->execute($get_dp_accounts_list_query);     while (!$get_dp_accounts_list->eof) {         $get_dp_accounts_listarray[] = array('account_id'=>$get_dp_accounts_list->fields['account_id']);         $get_dp_accounts_list->movenext();     }     foreach($get_dp_accounts_listarray $acc_list) {         $get_last_dp_entry_query = "select *             money_debt_planner             customer_id = '".$_session['customer_id']."'             , account_id = '".$acc_list['account_id']."'             order line_id desc";         $get_last_dp_entry = $db->execute($get_last_dp_entry_query);          if($get_last_dp_entry->fields['end_debt_balance'] <> 0) {             // calculate interest period             $accounts_balance = $get_last_dp_entry->fields['end_debt_balance'] + $get_last_dp_entry->fields['estimated_spending'];              $min_pay = $get_last_dp_entry->fields['min_pay_amount'];             $min_pay_rate = $get_last_dp_entry->fields['min_pay_rate'];             $interest_rate = $get_last_dp_entry->fields['interest_rate'];              $int_rate = $interest_rate /100;             $int_rate_a = $int_rate + 1;             $int_value_b = $accounts_balance ;             $int_value_c = ($int_rate_a * $int_value_b) - $int_value_b . '       ';             $int_value_d = $int_value_c / 12;              $statement_balance = $accounts_balance + $int_value_d;              $min_pay_rate = ($statement_balance) * $min_pay_rate / 100;              if($min_pay_rate < $min_pay) {                 $new_bill_amount = $min_pay;             } else {                  $new_bill_amount = $min_pay_rate;             }             if(($statement_balance) <= ($min_pay_rate) && ($statement_balance) <= $min_pay) {                  $new_bill_amount = $statement_balance;             }              // next pay date              $next_due_day1 = date('d', strtotime ( $get_last_dp_entry->fields['date'] ));             $next_due_year_month1 = date('y-m', strtotime ( $get_last_dp_entry->fields['date'] ));              $next_due_month_a_1 = strtotime ( "+ 1 month" , strtotime ( $next_due_year_month1 ) ) ;             $next_due_month_b_1 = date ( 'y-m' , $next_due_month_a_1);             $total_days_in_this_month = date('t', strtotime($next_due_month_b_1) );              if($next_due_day1 >= $total_days_in_this_month) {                 $next_due_date_a_1 = $total_days_in_this_month;             } else {                  $next_due_date_a_1 = $next_due_day1;             }              $payment_date_from_account1 = $next_due_month_b_1 .'-' . $next_due_date_a_1;             $next_due1a = strtotime ( $payment_date_from_account1 ) ;             $next_due1 = date ( 'y-m-d' , $next_due1a );              $dp_pay_date = $next_due1; // 1 month last entry             $interest_this_period = $int_value_d; // interest on last end balance + est spending             $payment_this_period = $new_bill_amount; // min payment allowed including on credit amount             $end_balance = ''; // current open balance + spending + interest - payment              $sql = "insert `money_debt_planner` (`customer_id`, `account_id`, `date`, `open_debt_balance`, `interest_rate`, `min_pay_rate`, `min_pay_amount`, `credit_limit`, `estimated_spending`, `interest_this_period`, `payment_this_period`, `end_debt_balance`)             values ('".$_session['customer_id']."', '".$acc_list['account_id']."', '".$dp_pay_date."', '".$get_last_dp_entry->fields['end_debt_balance']."', '".$get_last_dp_entry->fields['interest_rate']."', '".$get_last_dp_entry->fields['min_pay_rate']."', '".$get_last_dp_entry->fields['min_pay_amount']."', '".$get_last_dp_entry->fields['credit_limit']."', '".$get_last_dp_entry->fields['estimated_spending']."', '".$interest_this_period."', '".$payment_this_period."', '".$end_balance."')";             $db->execute($sql);         } // end if balance 0     } // end account list      // total debt balance utstanding     $total_debt = $total_debt - 1000; } 

any can offer great :o)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -