简体   繁体   中英

Concatenate queries in SQL using PHP

I cannot spot the difference of these queries.

$lastact="SELECT * FROM DOC_DETAILS WHERE 1=1 AND DOC_TYPE=$emp_id";    
$whr="";

1. ...

$docfk=$emprow['ICID'];
$whr .= " AND DOC_TYPE=$docfk";
$qry1=mysqli_query($conn,$lastact .$whr);

...

2. ...

$qry1=mysqli_query($conn,"SELECT * FROM DOC_DETAILS WHERE 1=1 AND DOC_FK=$docfk");

...

the 1st query doesn't return any result while the 2nd works fine.

Thanks very much for any help.

The SQL in the first query will be

SELECT * FROM DOC_DETAILS WHERE 1=1 AND DOC_TYPE=$emp_id AND DOC_TYPE=$docfk

If emp_id and docfk are different this will return no results.

在第一个查询中,您添加“ DOC_TYPE = $ emp_id”,但在第二个查询中, “ DOC_TYPE = $ emp_id”未找到此条件,因此首先需要检查此条件,如果没有得到结果,请添加/删除,然后再次告诉我

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM