如何在php中选择两个表数据?

时间:2018-01-11 10:46:59

标签: php

要求: - >我想在锡的基础上选择两个表数据。我的日期为2017年12月23日至2017年12月29日。我想设置$query = "SELECT dt,entusr, attremark, empcode, compcode FROM NPINOUTSCR where entusr='".$entusr."' and empcode='".$empcode."' and compcode='".$compcode."' "; $result = oci_parse($con,$query); $exe = oci_execute($result); while($row= oci_fetch_assoc($result)) { $stmtb['DT']=$row['DT']; $stmtb['ENTUSR']=$row['ENTUSR']; $stmtb['ATTREMARK']=$row['ATTREMARK']; $stmtb['EMPCODE']=$row['EMPCODE']; $stmtb['COMPCODE']=$row['COMPCODE']; $stmtb['remark'] = array(); echo $stmtb['DT']; $q1 = "select to_char(tin, 'DD-MON-YYYY hh24:mm:ss') as tin, to_char(tout, 'dd-mm-yyyy hh24:mm:ss') as tout from npinout where compcode='".$compcode."' and empcode='".$empcode."' and to_char(tin, 'MON-YYYY') ='".$date."' and trunc(tin)='".$stmtb['DT']."' ORDER BY tin " ; $rs1=oci_parse($con,$q1); $ex1=oci_execute($rs1); while($row1= oci_fetch_assoc($rs1)) { if($stmtb['ATTREMARK']=='') { $stmtc['TIN']="A"; $stmtc['TOUT']="A"; } else { $stmtc['TIN']=$row1['TIN']; $stmtc['TOUT']=$row1['TOUT']; } array_push($stmtb['remark'],$stmtc); } array_push($final,$stmtb); } echo json_encode($final);

在锡中没有任何日期。

{{1}}

enter image description here

请告知。

1 个答案:

答案 0 :(得分:0)

不确定数据库sql,但您总是可以在查询中尝试if(statement,true,false):

"SELECT if(tin = defaultValue,'A',tin),..."

如果以前$stmtb['ATTREMARK'] = ''

,甚至运行查询似乎也是多余的