Reputation: 25
I have a function in a codeigniter controller that calls a model function with 3 parameters. Of the 3 passed parameters, response_num comes across blank when it should be an integer value. Hoping someone else's eyes can spot the trouble! Thanks! (I'm still learning php and codigniter).
Here is the calling function in the controller:
for($i=1; $i < $possible_results_count; $i++) {
print_r("iteration: ".$i);
$g1 = $this->Response_model->get_possible_results_for_response($i, $this->session->userdata("assess_id"), $this->session->userdata("user_id"));
print_r("Sum for ".$i."=".$g1["response_value"]);
if($g1["response_value"] >= $sensitivity) {
$results[$i] = $userdata["possible_results"][$i]; //
$result_count++;
// print_r("added [".$userdata["results"][$i]."]");
}
$total_results = $result_count;
if ($total_results >= $min_result_count) {
// print_r("found 3 gifts-breaking for loop");
break;
}
}
The called function in the model:
public function get_possible_results_for_response($*response_num*=FALSE, $assess_id, $registrant_id){
print_r("response_num=".$response_num."; assess_id=".$assess_id."; registrant_id=".$registrant_id);
$i is the variable in the calling functions for loop. the print_r's show all variables are correct except for the parameter that was passed as $i, it is blank. $i tracks the iteration count and passes it to the model for a db lookup using $i to determine which record to use in calculations.
Upvotes: 0
Views: 62
Reputation: 25
Solved! Right after I posted this question, I decided to initialize $i ($i=0) just before the for
loop and it worked -- the value was passed to the calling function.
Apparently using $i in the for
loop without initializing works for the for loop, but not as a regular variable unless it is initialized.
Upvotes: 0