gpt4 book ai didi

PHP、MySQL UNION 查询错误

转载 作者:行者123 更新时间:2023-11-29 13:57:32 24 4
gpt4 key购买 nike

我在尝试使用 PHP/MySQl-AJAX 调试此查询时遇到问题:变量 $param 是对表单文本框进行 AJAX 调用的结果。本质上,我试图对三个数据库表生成动态搜索,不幸的是,这三个数据库表具有不同的字段(因此是 concat)。这些数据是使用不同方法生成的具有空间位置(前两个表)的作业地址,最后一个表是非空间数据。

            $fetch = "(SELECT JobNo AS JobNo, CONCAT(Title1, '-', Title2, '-', Title3) AS Description, 'Hurricane' as type FROM Hurricanev2 WHERE Title1 REGEXP '$param' OR Title2 REGEXP '$param' OR Title3 REGEXP '$param') 
UNION ALL
(SELECT jobNo AS JobNo, description As Description, address As Geocoded_address, 'geocoded' as type FROM jr WHERE description REGEXP '$param' OR address REGEXP '$param')
UNION ALL
(SELECT job As JobNo, description As Description, 'plan' as type FROM register WHERE description REGEXP '$param')";


while ( $row = mysql_fetch_object( $fetch ) ) {

$sResults .= '<tr>';
$sResults .= '<td>' . $row['JobNo'] . '</td>';
$sResults .= '<td>' . $row['Description'] . '</td></tr>';
}

提前致谢

最佳答案

您无法合并具有不同列数的结果集。

尝试以下操作;

$fetch = "(SELECT JobNo AS JobNo, CONCAT(Title1, '-', Title2, '-', Title3) AS Description, 'Hurricane' as type, 'extra' FROM Hurricanev2 WHERE Title1 REGEXP '$param' OR Title2 REGEXP '$param' OR Title3 REGEXP '$param') 
UNION ALL
(SELECT jobNo AS JobNo, description As Description, address As Geocoded_address, 'geocoded' as type FROM jr WHERE description REGEXP '$param' OR address REGEXP '$param')
UNION ALL
(SELECT job As JobNo, description As Description, 'plan' as type, 'extra' FROM register WHERE description REGEXP '$param')";

关于PHP、MySQL UNION 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15607142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com