I’m trying to get the data from two tables after an “Open” button is clicked from previous table UI by sending an Id.
e.g.
<a name="Open" href="<?php echo base_url('welcome/WellProfile/'.$post->Id) ?>">
So I have two tables – namely “WellDataA” and “WellDataB” , I want to get the data where WellDataB data matches with the WellDataA by WellName(column).
Example:
WellDataA:
Id Platform WellName
.
.
4 ZE ZE-A
5 ZE ZE-B
6 ZE Ze-B
.
.
WellDataB:
Id WellName CompleteDate
1 ZE-A 12/3
2 ZE-B 14/5
3 ZE-C 20/6
This is how my query so far, but it ended up error
public function get_news_by_id($Id = 0)
{
if ($Id === 0)
{
$query = $this->db->get('WellDataA');
return $query->result_array();
}
$this->db->select('*');
$this->db->from('WellDataA');
$this->db->join('WellDataB','WellDataA.WellName =
WellDataB.WellName','INNER');
$query = $this->db->get_where('WellDataA', array('Id' => $Id));
return $query->row_array();
}
I expect the output would show ZE, ZE-A, 12/3 when “Open” button is clicked on ZE-A. But the actual output is ZE, ZE-A only. Thank you so much in advance!:)
3
Answers
Firstful I am sorry if my solution won’t be a good one,
but I suggest you change the structure of your tables to this:
Since I assume that the used model is relational, one thing must first achieved is to make the tables all relational. Instead of connecting WellDataA and WellDataB with the Id from WellDataB inside WellDataA.
Try this, your issue is in get_where() so, i removed it and rewrite it
I think you just need to remove some code. Just try this code