我有3个表查询,并检查是否有一个值使用相同的变量在三个表中的一个。此刻,我能想到的是用if else condition
来检查。下面是例子,PHP - 简单和整洁的方式来检查是否.. else条件
if (isset($post_val)) {
$var= /* mysql queries table 1 */
}
if (empty($var)) {
$var= /* mysql queries table 2 */
if (empty($var)) {
$var= /* mysql queries table 3 */
}
}
是否有更短或干净的方式来做到这一点。
更新代码
其实,我使用WordPress的,从是CFDB
插件。我的实际代码将会是。
if (isset($vehicle_no)) {
$location = do_shortcode('[cfdb-value form="season parking form_copy" filter="your-platno=' . $vehicle_no . '"');
}
if (empty($location)) {
$location = do_shortcode('[cfdb-value form="season parking form" filter="your-platno=' . $vehicle_no . '"');
if (empty($location)) {
$location = do_shortcode('[cfdb-value form="Season Register 2017" filter="your-platno=' . $vehicle_no . '"');
}
}
也许['UNION'](https://www.tutorialspoint.com/sql/sql-unions-clause.htm)可能对你的情况有用。 –
@AlexHowansky感谢您的想法和链接。将通过它看。 – Amran
@AlexHowansky我更新我的问题 – Amran