我正在建立一个Mysql全文搜索,我有4个表搜索。当我在搜索查询中只使用一个表时,它可以工作,但当我在查询中使用多个表时,它不起作用。此外,我不想在查询中使用UNION ALL,因为我使用复选框选择选项在单个或多个表中执行搜索。
对多个表的MySQL查询不起作用。
$sqlquery = mysql_query("(SELECT * FROM table1, table2, table3, table4 WHERE MATCH (pflink, title) AGAINST ('%$keyword*%' IN BOOLEAN MODE) )ORDER by pflink desc, $orderby $sortby LIMIT $rowsperpage OFFSET $offset ")or die (mysql_error());它给出了错误Column 'pflink' in where clause is ambiguous
使用单表查询是可行的。
$sqlquery = mysql_query("(SELECT * FROM table1 WHERE MATCH (pflink, title) AGAINST ('%$keyword*%' IN BOOLEAN MODE) )ORDER by pflink desc, $orderby $sortby LIMIT $rowsperpage OFFSET $offset ")or die (mysql_error());Html复选框代码
<input name="all-tables" type="checkbox" value="true" checked="checked" id="check-all" >
<input name="table1" type="checkbox" value="true" disabled="disabled" >
<input name="table2" type="checkbox" value="true" disabled="disabled" >
<input name="table3" type="checkbox" value="true" disabled="disabled" >
<input name="table4" type="checkbox" value="true" disabled="disabled" >请建议任何可能的方法来修改此查询,使其适用于多个表。
谢谢。
发布于 2012-08-10 16:55:14
很久以前,我也遇到过类似的情况。我有多个表可以使用全文,但我不知道如何做我想要的。我找了找,但找不到路。所以最后我想出了下面的想法
1. Make another table say "keywords", with fields title, description , item_id, and the table data belongs to.
2. make a code to fetch all title and description from table1,table2 and so on and insert it to keywords.
3. Make keywords table suitable for full text search.
4. when user searches, search keyword table. Retrieve relevant value from table1, table 2 etc from the recordset (as you get item id and table from the full text search query).这样做的好处是查询将更快和更容易。
希望这能有所帮助
https://stackoverflow.com/questions/11897969
复制相似问题