views:

55

answers:

2

I have many goals to be printed on the screen. but it shows error when i use it like this

echo $this->validation->rshort_goal.$i;

What is the right way to use this?

if($sgoal !='')
{
    $scount = count($sgoal);
    $i =1;
    foreach($sgoal as $row)
    {
      <textarea name="rshort_goal<?php print $i;?>" id="short_goal" class="short_go">
      <?php if($this->validation->rshort_goal.$i)
                { 
                  echo $this->validation->rshort_goal.$i;
                }             
               elseif($this->validation->rshort_goal.$i._error !='') 
               { echo ''; } 
               else 
               {echo $$row->goal_description; }
           ?>
     </textarea>
        <?php
    $i++;
    }
}
+1  A: 

Perhaps you want to call a function like this?

call_user_func($this->validation, 'rshort_goal' . $i);
strager
Its not working. Because it will work if i put $this->validation->rshort_goal1. This 1 has to in a loop like 1,2,3
ASD
@Suj, I see what you're trying to do now. Perhaps this helps?
strager
+1  A: 
echo @$this->validation->{'rshort_goal'.$i};
Phil Sturgeon
Great! It worked.
ASD