Code :
SELECT l.hcode,l.pcucode,replace(l.house,'/','-') AS lhouse,l.vhid,p.pid,p.prename,p.fname,p.lname,p.birth,p.age,p.sex,p.cid,p.hosmain,replace(p.house,'/','-') AS phouse,h.offname1,h.moo,h.provname,h.ampurname,h.tambonname,h.vhidname
FROM ".$layer." AS l
INNER JOIN person AS p ON l.vhid=p.vhid AND replace(l.house,'/','-')=replace(p.house,'/','-') AND l.pcucode=p.pcucode
INNER JOIN hoffice AS h ON l.pcucode=h.off_id
WHERE replace(p.house,'/','-') = replace(substr(".$fldValue.",1,char_length(".$fldValue.")-8),'/','-') AND p.vhid = substr(".$fldValue.", char_length (".$fldValue.") -8 +1,8);