MySQL Full Textsearch多个字段

时间:2011-11-10 22:27:35

标签: mysql full-text-search

我有一些这样的表:

car/model
Audi A2 2.0 TDI
Audi A8 2.5 TDI
Audi A6 4.2 V8

从PHP我得到这个var:'Audi A8'

当我运行此查询时:

select * from cars where match(car, model) against ('Audi A8') 

MySQL返回:

Audi A2 2.0 TDI
Audi A8 2.5 TDI
Audi A6 4.2 V8

我只想要'奥迪A8 2.5 TDI'。我该怎么做?

1 个答案:

答案 0 :(得分:1)

将值拆分为firstname和lastname:

$names = explode( ' ', $value );
$firstname = mysql_real_escape_string( $names[ 0 ] );
$lastname = mysql_real_escape_string( $names[ 1 ] );

并运行查询:

mysql_query( "SELECT * FROM people WHERE Firstname = '$firstname' AND Lastname = '$lastname'" );