Welcome Guest, Not a member yet? Register   Sign In
Join Problem
#1

[eluser]Kfrico[/eluser]
Code:
function select_pmacm($data)
    {
        
    $PersonID = $data->PersonID;  
      
    $this->load->database();
    $this->db->select('*');
    $this->db->where('PersonMaster.PersonID =',$PersonID);
    $this->db->from('PersonMaster');
    $this->db->join('AssocChairMan', 'AssocChairMan.PersonID = PersonMaster.PersonID ');    
    $query = $this->db->get();
    return $query;
    
    }

Code:
foreach($pmdata->result() as $pmrow)

Why to appear

Fatal error: Call to a member function result() on a non-object in
#2

[eluser]MMacdonald[/eluser]
I think there's more than a join problem going on here. Let's fix the other problems first. I always suggest you get the simplest query working intially, and then build it up to the one you want.

Your error message is telling you that $pmdata doesn't exist - which appears to be the case from the code you submitted. Follow this simple template for a single table, and let me know how you get on. If you get that far, we can look at joins with other tables:

In your model (which I've called example_model.php - the class is Example_model)

Code:
function select_item($id)
{
  $this->load->database();
  $this->db->select('*'); //get all table fields
  $this->db->where('id',$id); //for the single item that matches the $id
  $query = $this->db->get('example_db_table_name'); //pass the table name - you were missing this
  //you might want to check that only 1 row was returned - add code later
  return $query->result(); //I return the result, rather than the query object
}

In your controller:

Code:
$this->load->model('example_model');
$data['item']=$this->example_model->select_item($id);
$this->load->view('example_view',$data);

In your view (which I've called example_view.php - the class is Example_view)

Code:
//you only wanted one row - so you work with the first item in the result array
//if you had requested all rows in the table, you could use a nested loop to go through
//each element in each row
foreach ($item[0] as $fieldname)
{
  echo $fieldname;
}

Let me know how you get on.

Mark
#3

[eluser]Kfrico[/eluser]
Controllers

Code:
$this->load->model('modelacm');
    $query['data'] = $this->modelacm->select_acm($data);    
    $this->load->view('view_acmdata',$query);
    $this->login_acm();
Model

Code:
function select_acm($data)
    {
    $PersonID = $data->PersonID;  
    $Status = $data->Status;                              
    $AssocChairType = $data->AssocChairType;            
    $AssocChairManID = $data->AssocChairManID ;      
                  
    $this->load->database();
    $this->db->select('*');        
    $this->db->where('"AssocChairMan"."PersonID" = ',$PersonID);
    $this->db->or_where('"AssocChairMan"."Status" = ',$Status);
    $this->db->or_where('"AssocChairMan"."AssocChairType" = ',$AssocChairType);
    $this->db->or_where('"AssocChairMan"."AssocChairManID" = ',$AssocChairManID);
    $this->db->from('AssocChairMan');
    $this->db->join("AssocChairMan", "AssocChairMan.PersonID = PersonMaster.PersonID");        
    $query = $this->db->get();
        return $query;
    
    }

View

Code:
foreach($data->result() as $row){
    echo '<TD align=left>';
    echo  $row->PersonID;
    echo  '</TD>';
    echo '<TD align=left>';
    echo  $row->ChineseName;
    echo  '</TD>';
    echo '<TD align=left>';
    echo  $row->Sex;
    echo  '</TD>';
    echo '<TD align=left>';
    echo  $row->Status;
    echo  '</TD>';
}
#4

[eluser]MMacdonald[/eluser]
I'm not clear on what the outcome was. Are you posting the working solution for the benefit of other readers or are you still needing help?
#5

[eluser]Kfrico[/eluser]
Not too understand your meanings, can be more definitely calling me to see

I beat to still appear like this

Call to a member function result() on a non-object in

Code:
foreach($data->result()  as $row)
#6

[eluser]Kfrico[/eluser]
Exactly paid wrong there

How should I modify




Theme © iAndrew 2016 - Forum software by © MyBB