user_g
user_g

Reputation: 35

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.

Upvotes: 1

Views: 70

Answers (2)

Avinash Kalola
Avinash Kalola

Reputation: 113

In the first query you add "DOC_TYPE=$emp_id" but in second query "DOC_TYPE=$emp_id" this condition not found so first need to check this condition add/remove if not getting result then tell me again

Upvotes: 0

Joni
Joni

Reputation: 111219

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.

Upvotes: 1

Related Questions