Welcome Guest, Not a member yet? Register   Sign In
problem with getting query results on to the view page
#1

[eluser]Bhavani Shekhawat[/eluser]
site Controller
Code:
function show_my_artifacts()  // Displays artifacts entered by me
          {
         $this->members_area();
         $this->load->model('artifact_model');
           $data['values'] =  $this->artifact_model->fetch_myArtifacts();
           $this->load->view('display_myartifacts', $data);
          }
  }

artifact_model Model
Code:
function fetch_myArtifacts(){
        
        $get_userID_session = $this->session->userdata('username');
        
        $query = $this->db->query("SELECT artifact.ArtifactName, artifact.ArtifactID, artifact.EnteredDate,
        ca_table.username FROM artifact,ca_table WHERE ca_table.ArtifactID = artifact.ArtifactID AND
            ca_table.username = '$get_userID_session'
     ");
    
      if ($query->num_rows() > 0){
        
         foreach ($query->result() as $rows)
             {
                 $data[] = $rows;
             }
             return $data;
     }
        
        else
            {
                return false;
            }
    }


display_myartifacts view
Code:
<p> Your Artifacts </p>

&lt;? foreach ($row as $r): ?&gt;
                
&lt;? echo $r->ArtifactName; ?&gt;

&lt;? endforeach; ?&gt;

I dont know why I am not getting any query data on my view page. If I straight away display results in the model function it works but thats not what I want. I guess I am making some mistake in passing the data into the view in my controller. May be you people can help me out. Peace!
#2

[eluser]LuckyFella73[/eluser]
The array with DB data available in your view is called "$values" and not "$row"!

Remember your line in your controller:
Code:
$data['values'] =  $this->artifact_model->fetch_myArtifacts();
#3

[eluser]WanWizard[/eluser]
$row does not exist in your view, you don't pass a variable called 'row' to it.

Based on your example it should be
Code:
<p> Your Artifacts </p>

&lt;? foreach ($values as $r): ?&gt;
                
&lt;? echo $r->ArtifactName; ?&gt;

&lt;? endforeach; ?&gt;
#4

[eluser]Bhavani Shekhawat[/eluser]
Thanks guys, I changed that but now I get following message.

Your Artifacts

ArtifactName; ?&gt;
#5

[eluser]LuckyFella73[/eluser]
I'm not familiar with your style of using foreach, try this one,
maybe you have luck:

Code:
<p> Your Artifacts </p>

&lt;?php
foreach ($values as $r)
{
    echo $r->ArtifactName;
}
?&gt;
#6

[eluser]WanWizard[/eluser]
Because you have a syntax error in your view?

Code:
<p> Your Artifacts </p>

&lt;?php foreach ($values as $r): ?&gt;
                
&lt;?php echo $r->ArtifactName; ?&gt;

&lt;?php endforeach; ?&gt;
#7

[eluser]Bhavani Shekhawat[/eluser]
Thanks guys but I found the problem.




Theme © iAndrew 2016 - Forum software by © MyBB