我有这样的桌子:

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

从PHP我得到这个变量:“奥迪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”。我该怎么做?

最佳答案

将值拆分为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'" );

10-08 08:49
查看更多