我有一个SQL查询,其中imputs是由用户通过搜索表单生成的。
// Select some data
$sth = $dbh->prepare("SELECT `id`, `type_code`, `connector_type`, `construction_type`, `author`, `estimate_lead_time`, `last_update`, `confidence_level`, `start_passband`, `stop_passband`, `low_passband`, `high_passband`
FROM `filter_bandpass`
WHERE (`start_passband` = $lowfreq AND `stop_passband` = $highfreq)");
我试图让它允许用户只填写$lowfreq
,而不填写$highfreq
,结果将显示用户插入数据的$lowfreq =
的所有结果,但当他们输入$highfreq
的数量时,结果会显示两者。
因此$highfreq包含数据或为空。然后简单地更换
WHERE (`start_passband` = $lowfreq AND `stop_passband` = $highfreq)");
带有
WHERE (`start_passband` = $lowfreq AND (`stop_passband` = $highfreq OR $highfreq = ''))");