Welcome Guest, Not a member yet? Register   Sign In
Quick question! Multiple tables
#1

[eluser]Paleleaves[/eluser]
Hi,

I've a model. Pls see the code below

Code:
<?php
class Articles_model extends Model
{
  function Articles_model()
  {
      parent::Model();
      $this->load->database();
  }
  
function list_participants($num, $offset)
  {
      

$query = $this->db->get('property', $num, $offset);
      return $query;
  }
}
?>

It's working fine but I need pass multiple tables in the place of 'property' in my model. see the code below.

Code:
SELECT * FROM property, district, ptype WHERE property.reqType = ptype.pID AND property.districtName = district.dID

Anybody can help me to modify my model using this query. thanks
#2

[eluser]thdls55[/eluser]
Hi,
you need to use:

Code:
$this->db->join();

as shown here.
#3

[eluser]Paleleaves[/eluser]
Hi,

thanks for the help. But it didn't work at all. I've changed the <Model> like below.

Code:
&lt;?php
class Articles_model extends Model
{
  function Articles_model()
  {
      parent::Model();
      $this->load->database();
  }
  
function list_participants($num, $offset)
  {
      

$query = $this->db->join('SELECT * FROM property, district, ptype WHERE property.reqType = ptype.pID AND property.districtName = district.dID', $num, $offset);
      return $query;
  }
}
?&gt;

I spent many hours to correct this issue and tried different methods! :red:
#4

[eluser]kikz4life[/eluser]
what thdls55 saying is you must use join statement to select data from different tables.

Code:
$this->db->join('tablename1 a', 'a.fieldname1=tablename2.fieldname', 'left')
.......
then

select ....




Theme © iAndrew 2016 - Forum software by © MyBB