How do I input in SQL where I got this 2 tables, table a and table b.
table a:
+----+-------+--------+--------+
| id | name | data1 | data2 |
+----+-------+--------+--------+
table b:
+----+------------+-------+--------+--------+
| id | member_id | a_id | data1 | data2 |
+----+------------+-------+--------+--------+
So I want to get all the values from table a.
I also want to get data2 and value = true
from table b where a.id = b.a_id.
If a data from table a doesn't have a value from table b where a.id = b.a_id, data2 = 0, value = false.
If this could all happen using SQL that would be great but if not, at least tell how you would solve the problem using PHP or codeigniter or just post your concept/algorithm. Thank you in advance.
Edit2:
Okay I got it. Thanks everyone below who shared their ideas. They helped a lot:
model:
function getData2(){
$id = $this->uri->segment(3);
$this->db->select("t.*, mt.mid as mid, mt.amt as mtamt");
$this->db->from("transaction as t");
$this->db->join("mtrans as mt", "mt.tid = t.id and mt.mid = '$id'", "left outer");
$query = $this->db->get();
$data['info2'] = $query->result_array();
return $data;
}
view:
<?php foreach ($info2["info2"] as $record) { ?>
<tr>
<td><?php echo $record["id"]; ?></td>
<td><?php echo $record["name"]; ?></td>
<td><?php echo $record["type"]; ?></td>
<td><?php echo $record["amt"]; ?></td>
<?php foreach ($info1["info1"] as $stat) {
if($record["mid"] == $this->uri->segment(3)){?>
<td><?php echo $stat["mtamt"]; ?></td>
<td><?php echo $stat["user"]; ?></td>
<td><?php
if(!$stat["mtamt"]){
echo "Unpaid";
}
if($stat["mtamt"] < $record["amt"]){
echo "Partial";
}
if($stat["mtamt"] == $record["amt"]){
echo "Paid";
}
?></td>
<?php } } ?>
</tr>
<?php } ?>