我有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