4
我試圖讓我的全文搜索按相關性排序。這裏是我的代碼,它的工作原理是如果刪除ORDER BY,但不按相關性排序。我已經嘗試過,它實際上使它不會找到任何結果......任何想法?MYSQL全文搜索順序的相關性
$query_for_result=mysql_query("
SELECT * FROM Assets WHERE MATCH
(`Badge`,`First Name`,`Last Name`,`Service Tag`,`Asset Tag`)
AGAINST ('".$query."*' IN BOOLEAN MODE) and
`deleted` = '0' ORDER BY relevance DESC");
編輯*
<input type="text" name="query" />
<input type="hidden" value="Search" name="submit" />
<input type="submit" name="submit" value="Search" />
</form>
<h4>Search by: Badge, First or Last Name, Service Tag, Asset Tag, Printer Queue or Printer IP.</h4>
<br>
</center>
<?php
if(isset($_GET['submit'])){
$db_tb_name=Assets;
$db_tb_atr_name=`First Name`;
$query=mysql_real_escape_string($_GET['query']);
$query_for_result=mysql_query("
SELECT * FROM Assets WHERE MATCH
(`Badge`,`First Name`,`Last Name`,`Service Tag`,`Asset Tag`)
AGAINST ('".$query."*' IN BOOLEAN MODE) and
`deleted` = '0' ORDER BY relevance DESC");
後來在代碼
while($data_fetch=mysql_fetch_array($query_for_result))
{
print '<h3>';
print "<a href=\"modify.php?id=" . $data_fetch['id'] . "\">" . $data_fetch['First Name'] . ' ' . $data_fetch['Last Name'] . "</a>";
print '<br/><b>Badge:</b> '. $data_fetch['Badge'];
print '<br/> <b>Service Tag:</b> '. $data_fetch['Service Tag'];
print ' <b>Asset Tag:</b> '. $data_fetch['Asset Tag'];
print '<br/> <b>Status:</b> '. $data_fetch['Status'];
print '<br/><b>Employee Status: </b>';
if($data_fetch['Employee Status'] == 'Active'){
print '<font color="#32CD32">' . $data_fetch['Employee Status'] . '</font>';
}
elseif($data_fetch['Employee Status'] == 'Terminated'){
print '<font color="red">' . $data_fetch['Employee Status'] . '</font>';}
print '<br/> <b>Last Modified:</b> '. $data_fetch['Last Modified'];
print "<span> </span>";
print '</h3>';
print '<br/><p>' ;
}
UPDATE 這爲我工作 我終於得到它通過使用
工作感謝您的幫助
感謝,但由於某種原因,這仍然會導致沒有行發現 – user1548769
@ user1548769您可以共享不返回結果的查詢? – Tchoupi
我編輯並添加了一些額外的代碼 – user1548769