Welcome Guest, Not a member yet? Register   Sign In
foreach and array error can someone help me please
#1

[eluser]Miguel Diaz[/eluser]
Hi I am trying to save some information in my database depending of an information I have on a table but it doesnt work, I am not to good with php and this is for my job I apprecciate all the help you can give me thanks.

Controller
Code:
$names = $this->db->query("select encuestaPreguntaID from encuestaPregunta where encuestaID='1'");

  $info = array(
  foreach ($names->result() as $row):
   $_POST['txt'.$row->encuestaPreguntaID]);
  endforeach;
  );
  
  
  foreach ($info as $value):
        $data = array(
    'encuestaPreguntaID' => $this->input->post('encuestaID'),
    'respuesta'    => $value
            );
  $this->db->insert('encuestaRespuesta', $data);
        endforeach;
  
  echo 'Done';

Thanks in advance
#2

[eluser]vbsaltydog[/eluser]
[quote author="Miguel Diaz" date="1327878362"]
Code:
$info = array(
  foreach ($names->result() as $row):
   $_POST['txt'.$row->encuestaPreguntaID]);
  endforeach;
  );
[/quote]

The quoted code is wrong.
#3

[eluser]pickupman[/eluser]
Here's a little help.
Code:
$names = $this->db->select("encuestaPreguntaID")->where("encuestaID",'1')->get("encuestaPregunta")->result(); //Use ActiveRecord

  $info = array();
  foreach($names as $row):
  
    $info[] = $this->input->post('txt'.$row->encuestaPreguntaID); //Add the $_POST['txt'.questionID] values to the info array
  endforeach;  
  
  foreach ($info as $value):
        $data = array('encuestaPreguntaID' => $this->input->post('encuestaID'),
                      'respuesta'    => $value
                      );
        $this->db->insert('encuestaRespuesta', $data);
  endforeach;
  
  echo 'Done';




Theme © iAndrew 2016 - Forum software by © MyBB