Welcome Guest, Not a member yet? Register   Sign In
Form radio buttons will not validate, need help.
#11

[eluser]CroNiX[/eluser]
Depends on how you called it. If you were using this function:
Code:
public function survey_results()
{
  $name = $this->session->userdata('name');

  //needs to be an array to pass to the view
  $data['HygieneCount'] = $this->User_Model->count_hygiene_factor($name);

  
  $this->load->view('factors_survey/survey_results', $data);
}
Then in your 'survey_results' file, just
Code:
echo $HygieneCount;
#12

[eluser]Judgestar[/eluser]
Cronix, I am hoping you can help me one more time. I am getting the results array from my count on the webpage, but it shows up as only an array. I did a print_r to debugg the problem and I am seeing the count in the array but it is not displaying correctly. Wondering if you can see where I went wrong.

controller is as you suggested:

Code:
public function survey_results()
{
  $name = $this->session->userdata('name');
  $data['HygieneCount'] = $this->User_Model->count_hygiene_factor($name);
  
  $this->load->view('factors_survey/survey_results', $data);
}

the model function you suggested did not work, it kept giving me an error when I did
Code:
return $q->total;
but this ended up working and is showing the array just not what I want to see exactly:

Code:
$sql = "SELECT SUM(Factor2Score + Factor5Score + Factor6Score + Factor8Score + Factor9Score + Factor12Score) AS total
      from FactorSurveyScore
      where Name = ?";
  
  $query = $this->db->query($sql, $name);

  if ($query->num_rows > 0)
  {
   return $query->result();
  }
  else
  {
   return 0;
  }

in the view it's a simple p tag and also a print_r to see what's in the array for debug purposes.

Code:
<p>Your Hygiene Factor Score is: &lt;?php echo $HygieneCount; ?&gt; &lt;?php print_r($HygieneCount); ?&gt;

and this is the output on the webpage:

Your Hygiene Factor Score is: Array Array ( [0] => stdClass Object ( [total] => 30 ) )

as you can see the 30 from the questions is there ( and is the correct data) but I am not able to show that data from the array for some reason. What am I missing that is preventing the data from showing correctly?


#13

[eluser]CroNiX[/eluser]
Well, you're only returning the result set (which is an array of objects) and not the individual value.

What is the output of &lt;?php print_r($HygieneCount); ?&gt;
#14

[eluser]Judgestar[/eluser]
the output is this: Array ( [0] => stdClass Object ( [total] => 30 ) )
#15

[eluser]CroNiX[/eluser]
Code:
if ($query->num_rows() == 1)
{
  $data = $query->result();
  return $data[0]->total;
}
#16

[eluser]Judgestar[/eluser]
Awesome Smile Thank you, that did it!

So basically you sent the results of the query to the array and then told the array to return the position with the correct data that was called 'total'? Asking to make sure I understand how that was done, so I can learn.
#17

[eluser]CroNiX[/eluser]
Yep. Probably could have just done:
Code:
return $query->row()->total;
as well.




Theme © iAndrew 2016 - Forum software by © MyBB