Welcome Guest, Not a member yet? Register   Sign In
Function Not Returning Result to Another
#1

[eluser]kingnutter[/eluser]
The following section of my model shows where I would like function GetLinks to call a result from the previous function, getInstanceRef.

The view gives Error Number: 1054 -Unknown column 'Array' in 'where clause' (SELECT * FROM (`links`) WHERE `instance_id` = Array)

I've seen this in regular PHP but not sure how to sort it in an MVC setup.

Any tips would be very appreciated.

Code:
function getInstanceRef()
        {
            $this->db->select('instances.id as iid');
            $this->db->where('instances.url', $this->uri->segment(3));
            $this->db->where('projects.url', $this->uri->segment(2));
            $this->db->from('instances');
            $this->db->join('projects', 'instances.project_id = projects.id');
            $this->db->limit(1);
            $query = $this->db->get();
            
                if ($query->num_rows() <1)
            {
                // show_error('Database is empty!');
            }else{
                return $query->result_array();
            }
        }

        function getLinks()
        {
                
            $this->db->select();
            $this->db->where('instance_id', $this->projects_model->getInstanceRef());
            $this->db->from('links');
            $query = $this->db->get();
            
            if ($query->num_rows() <1)
            {
                //show_error('Database is empty!');
            }else{
                return $query->result();
            }
    }
#2

[eluser]John_Betong_002[/eluser]
Try this:

Code:
//=================================
class Model_giving_problems extends CI_Model
{

  private $result_to_be_passed = 'DEFALT value to see if it works';

//=================================
function getInstanceRef()
{
  $this->result_to_be_passed = 'NEW value from: ' . __METHOD__ ;

// not required
// return  
}//endfunc


//=================================
function getLinks()
{
  echo '<b>Before:</b> ' .$this->result_to_be_passed;
  echo '<br /><br /><br />';

  $this->getInstanceRef(); //

  echo '<b>After:</b> ' . $this->result_to_be_passed;
  echo '<br /><br /><br />';
  die;
}//endfunc
&nbsp;
&nbsp;
&nbsp;
#3

[eluser]kingnutter[/eluser]
Thank you very much for this. I'm fairly new to CI so I hope you don't mind me asking a couple of questions about your code.

I haven't come across the word "private" before a function. Why is that used before $result_to_be_passed.

Is $this->result_to_be_passed in getInstanceRef just calling a variable? Why use "$this"->?

What should I putting in the place of "__METHOD__"?

Basically I'm just trying to understand what these three stages are doing. Sorry if it is all really obvious but it would really help me understand the process.

Thanks again.
#4

[eluser]John_Betong_002[/eluser]
[quote author="kingnutter" date="1309213273"]Thank you very much for this. I'm fairly new to CI so I hope you don't mind me asking a couple of questions about your code.

I haven't come across the word "private" before a function. Why is that used before $result_to_be_passed.

Is $this->result_to_be_passed in getInstanceRef just calling a variable? Why use "$this"->?

What should I putting in the place of "__METHOD__"?

Basically I'm just trying to understand what these three stages are doing. Sorry if it is all really obvious but it would really help me understand the process.

Thanks again.[/quote]
&nbsp;
&nbsp;
http://www.php.net/manual/en/language.oo...bility.php


With your code try this:
Code:
// correct
   $this->getInstanceRef();

// incorrect
   $this->projects_model->getInstanceRef();
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB