Welcome Guest, Not a member yet? Register   Sign In
Help - Problem with join & sql statement
#1

[eluser]sayo[/eluser]
This section of the code in where makes
the query return no result:

'table1.invoice'=>'table2.invoice'

What am i doing wrong?

Code:
public function customer($offset, $limit = 20)
{
  
  $this->db->select('table.name as username, table.useremail as email, table.OrderDate as date');
  $this->db->from('table');
  $this->db->join('table2', 'table2.uid = table.userid');

  $this->db->where(array('table.confirm'=>1, 'table2.order'=>'buy', 'table1.invoice'=>'table2.invoice'));

  $this->db->limit($limit,$offset);
  $query = $this->db->get();
  
  if($query->num_rows() == 0) return FALSE;
  return $query->result();
}
#2

[eluser]aquary[/eluser]
I can imagine nothing without a sample data .-.

btw, you can move the "where" part related to table2 inside the joining condition.
#3

[eluser]sayo[/eluser]
Thanks.

Placing the where inside the
joining condition solved the problem.

Code:
$this->db->join(‘table2’, ‘table2.uid = table.userid AND table1.invoice = table2.invoice’);
#4

[eluser]Mauricio de Abreu Antunes[/eluser]
Please, edit your code and put it into code tags.
Bye!




Theme © iAndrew 2016 - Forum software by © MyBB