class Func{
public function getTable_join($tb1,$tb2,$fid,$fname,$fid1,$id1,$fid2,$id2){
$sql = "select sum(b.$fname) from
$tb1 as a,$tb2 as b
where a.$fid = b.$fid
and b.$fid1 = '$id1'
and a.$fid2 = '$id2'
";
$fetch = mysql_fetch_array(mysql_query($sql))or die($sql);
return $fetch[$fname];
}
}
/*
select b.poll_id from tb_poll as a,tb_poll_dt as b where a.sum(poll_price) = b.sum(poll_price) and b.poll_num = 'A[0]' and a.poll_chk = '0'
*/ แปลงจาก SQL
class Func{
public function getTable_join($tb1,$tb2,$fid,$fname,$fid1,$id1,$fid2,$id2){
$sql = "select sum(b.$fname) as total from
$tb1 as a,$tb2 as b
where a.$fid = b.$fid
and b.$fid1 = '$id1'
and a.$fid2 = '$id2'
";
$fetch = mysql_fetch_array(mysql_query($sql))or die($sql);
return $fetch["total"];
}
}
เพิ่มให้อีก 1 ทางเลือกครับ
public function getTable_join2($tb1,$tb2,$fid,$fname,$fid1,$id1,$fid2,$id2){
$sql = "select sum($tb2.$fname) as total from $tb1
Inner Join $tb2 On $tb1.$fid = $tb2.$fid
where $tb1.$fid1 = '$id1' and $tb2.$fid2 = '$id2'
";
$fetch = mysql_fetch_array(mysql_query($sql))or die($sql);
return $fetch["total"];
}