注意:更新,因为我认为我需要使用类似于 CASE 的东西
我有一个具有 3 个地址输入的表单:
- 市郊
- 邮政编码
- 状态
我想使用这 3 个表单字段来填充 sql 查询的 where 子句(见下文)。
- 因此,如果没有输入任何输入字段,则没有 where 子句(并且所有行都被获取)
如果输入了一个或多个输入字段,则使用输入的 PHP 变量构建 where 子句。
$sql = <<<SQL SELECT cs.customerRefId, cc.firstName, cc.lastName, cc.email, cc.phone, cc.mobile, cs.seekingAddressSuburb, cs.seekingAddressPostcode, cs.seekingAddressState FROM customer_seeking cs LEFT JOIN customer_contact cc ON cc.customerRefId = cs.customerRefId WHERE cs.seekingAddressSuburb = $suburb cs.seekingAddressPostcode = $postcode cs.seekingAddressState = $state SQL;