我使用此代码来计算一个人在数据库中出现的次数(跨越 15 列)。
$name = "Clint Irwin";
$query = mysqli_query($con, "
SELECT * FROM `players`
WHERE MATCH (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15)
AGAINST ('$name' IN BOOLEAN MODE)
AND rank <= 1000");
$result = mysqli_num_rows($query);
echo $name.' '.$result;
这行得通......但是,我想让它更容易,这样我就可以在很多不同的名字上运行它......所以我尝试了这个......
function gw($name)
{
$query = mysqli_query($con, "
SELECT * FROM `players`
WHERE MATCH (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15)
AGAINST ('$name' IN BOOLEAN MODE)
AND rank <= 1000");
$result = mysqli_num_rows($query);
echo $name.' '.$result;
}
//run it for certain person names,
gw("Clint Irwin");
它不起作用。我刚刚收到以下错误消息
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/XAMPP/xamppfiles/htdocs/test.com/index.php on line 19
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/test.com/index.php on line 21
Clint Irwin
知道如何让它工作吗?解决起来似乎很简单,但我就是想不通。