将搜索结果分配到变量-PHP全文搜索布尔值

将搜索结果分配到变量-PHP全文搜索布尔值,php,mysql,full-text-search,search-engine,Php,Mysql,Full Text Search,Search Engine,我使用PHP/MySQL以布尔模式创建了全文搜索。它运行得很好,关联性排名和索引都分配给了相关的数据库字段。该数据库包含两个表: 业务->姓名、描述、联系人、地址、序列号 *搜索术语*->术语、查询时间、搜索日期、结果 然后现在,我想获取所有搜索结果并将其分配给变量($results)。此$result将与搜索的术语、查询时间和日期一起存储到搜索术语表中 这是我的代码(没有$result) 函数搜索($term){ $term=mysql\u real\u escape\u字符串($term);

我使用PHP/MySQL以布尔模式创建了全文搜索。它运行得很好,关联性排名和索引都分配给了相关的数据库字段。该数据库包含两个表:

业务->姓名、描述、联系人、地址、序列号

*搜索术语*->术语、查询时间、搜索日期、结果

然后现在,我想获取所有搜索结果并将其分配给变量($results)。此$result将与搜索的术语、查询时间和日期一起存储到搜索术语表中

这是我的代码(没有$result)

函数搜索($term){
$term=mysql\u real\u escape\u字符串($term);
$startTime=微时间(真);
$query=mysql_query(“SELECT*,MATCH(Name)对布尔模式下的(+$term*)作为rel1,MATCH(Description)对布尔模式下的(+$term*)作为rel2,MATCH(Keywords)对布尔模式下的(+$term*)作为rel3从业务中匹配(Name,Description,Keywords)对布尔模式下的(+$term*)顺序为(rel1*0.60)+(rel2*0.25)+(rel3*0.15)DESC”)或die(mysql_error());
$endTime=微时间(真);
$queryTime=substr($endTime-$startTime,0,6);
if(mysql_num_rows($query)==0){
echo“未找到“$term.”

的结果; } 否则{ while($row=mysql\u fetch\u assoc($query)){ 回声“; $desc=substr($row['Description'],0100); $score=$row['rel1']+$row['rel2']+$row['rel3']; 回音“”$desc.…

”; } $numOfResult=mysql\u num\u行($query); echo“
”$numOfResult.”在“$queryTime.”秒内找到结果。

”; $ip=$\u服务器['REMOTE\u ADDR']; $query2=mysql_query(“插入搜索_项(项、查询时间、Ip)值(“$term”、“$QueryTime”、“$Ip”))或die(mysql_error()); } }

我是PHP新手,这是我的第一个应用程序。非常感谢你的帮助

您可以创建并将
$result
保存到数据库,如下所示:

/* Your code before the cycle... */

$result = array(); /* The array where to store results */
while($row = mysql_fetch_assoc($query)) {
    /* Your code for printing, just as posted... */
    $result[] = $row; /* Store the result row in the array */
}

/* The rest of your code, before second query... */

/* Serialize the result data and save it to database */
$result_serialized = mysql_real_escape_string(serialize($result));
$query2 = mysql_query("
    INSERT INTO search_term(Term, QueryTime, Ip, result) 
    VALUES('$term', '$queryTime', '$ip', '$result_serialized')
") or die(mysql_error());
但要小心:
$result
(因此,
$result\u序列化的
)可能非常大,这取决于结果类型和数量。确保你能应付。
search_term
DB表中的
result
字段必须是
TEXT
或更大的字符串数据类型列


阅读有关的信息

我添加了对
serialize()
unserialize()
的PHP引用(您必须使用此引用从数据库读回数据)。请使用答案投票号码下的勾号图标接受我的答案。
/* Your code before the cycle... */

$result = array(); /* The array where to store results */
while($row = mysql_fetch_assoc($query)) {
    /* Your code for printing, just as posted... */
    $result[] = $row; /* Store the result row in the array */
}

/* The rest of your code, before second query... */

/* Serialize the result data and save it to database */
$result_serialized = mysql_real_escape_string(serialize($result));
$query2 = mysql_query("
    INSERT INTO search_term(Term, QueryTime, Ip, result) 
    VALUES('$term', '$queryTime', '$ip', '$result_serialized')
") or die(mysql_error());