Welcome Guest, Not a member yet? Register   Sign In
Trying to get values from 2 different tables at same db
#1

[eluser]massi84[/eluser]
Hey, I'm trying to get values from 2 different tables.
Problem here is that I'm getting Fatal error: Call to undefined method CI_DB_mysqli_driver::num_rows() at line :if ($data->num_rows()>0) ...
If someone could point out me to right direction, i would appreciate it.



this is in model:
Code:
function test()
    {
    
    $short = $this->_altdb->get('table1');        
        
            
if ($short->num_rows()>0)
{                
    $i=0;
    foreach ($short->result() as $row)
    {
        $shorten = $row->column1;    
                    
        $data = $this->_altdb->like('column', $shorten);        

        if ($data->num_rows()>0)
        {        
            foreach ($data->result() as $row)
            {                
                          $name=$row->column2; // column 2 from                            table2                

// here need to put values at same variable $all_data

              $all_data[$i]['column1'] = $shorten;
              $all_data[$i]['column2'] = $name;
            }
        }
        $i++;
    }
   }                    
    
}

Might add that database configurations are correctly entered so basicly problem is in this function.

Hopefully its easy to read, thanks
Massi
#2

[eluser]Jan_1[/eluser]
why not join?
what do you get on print_r($short); ?
#3

[eluser]massi84[/eluser]
It gives correct values from $short.. but problem seems to be that it doesnt reconise $data.
Even $data = $this->_altdb->like('column', $shorten); gives correct values.

if ($data->num_rows()>0) gives fatal error.
#4

[eluser]mddd[/eluser]
num_rows() must be called on a database result object.
$this->db->like() doesn't return a result from the database.
You must use $data = $this->db->get('table_name') to get such a result!
#5

[eluser]massi84[/eluser]
Yeah thanks very much, I got it working.




Theme © iAndrew 2016 - Forum software by © MyBB