0) { $sql .= " AND (FIND_IN_SET(" . (int) $docId . ", coalesce(ipd_doc_list.doc_list, '')) OR i.r_doc_id = " . (int) $docId . " OR i.r_doc_id IS NULL OR i.r_doc_id = 0)"; } $res = $conn->query($sql); echo "SQL Query Output (" . $res->num_rows . " rows):\n"; while ($row = $res->fetch_assoc()) { print_r($row); }