匹配问题
我试图用 php 和 mysql 制作一个搜索引擎,我再次使用匹配。
然而我有一个问题(可能是语法)让我发疯。
这是代码:
<?php
$busqueda= $_GET["words"];
require("conectdb.php");
if ($busqueda<>''){
$trozos=explode(" ",$busqueda);
$numero=count($trozos);
if ($numero==1) {
$cadbusca="SELECT * FROM post WHERE contenido LIKE '%$busqueda%' OR titulo LIKE '%$busqueda%'";
} elseif ($numero>1) {
$cadbusca="SELECT * , MATCH ( 'titulo', 'contenido' ) AGAINST ( '$busqueda' ) AS Score FROM post WHERE MATCH ( 'titulo', 'contenido' ) AGAINST ( '$busqueda' ) ORDER BY Score DESC";
}
$result=(mysql_query($cadbusca));
while($info = mysql_fetch_array($result))
{
echo $info["id"]." ".$info["titulo"]." ".$info["contenido"];
}
}
?>
这是多个单词搜索后的错误:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home1/foodbook/public_html/search/wordsearch.php on line 19
字段设置为全文......
谢谢
im trying to make a search engine with php and mysql and im using match agains.
However im having a problem (probably syntax) that is driving me crazy.
Here is the code:
<?php
$busqueda= $_GET["words"];
require("conectdb.php");
if ($busqueda<>''){
$trozos=explode(" ",$busqueda);
$numero=count($trozos);
if ($numero==1) {
$cadbusca="SELECT * FROM post WHERE contenido LIKE '%$busqueda%' OR titulo LIKE '%$busqueda%'";
} elseif ($numero>1) {
$cadbusca="SELECT * , MATCH ( 'titulo', 'contenido' ) AGAINST ( '$busqueda' ) AS Score FROM post WHERE MATCH ( 'titulo', 'contenido' ) AGAINST ( '$busqueda' ) ORDER BY Score DESC";
}
$result=(mysql_query($cadbusca));
while($info = mysql_fetch_array($result))
{
echo $info["id"]." ".$info["titulo"]." ".$info["contenido"];
}
}
?>
here is the error after more than one word search:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home1/foodbook/public_html/search/wordsearch.php on line 19
The fields are set to fulltext....
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该警告意味着您的查询失败。如果查询失败,
mysql_query()
返回布尔值 FALSE,您可以使用mysql_error()
检索错误消息:您的代码假设查询成功并尝试获取行来自该错误值,该值不是有效的结果句柄。假设查询会成功是不好的做法。即使查询字符串在语法上是有效的,也可能会通过许多其他方式发生失败,并且您应该在每一步检查是否成功(或失败)。
The warning means that your query failed. If a query fails,
mysql_query()
returns boolean FALSE and you can retrieve the error message withmysql_error()
:Your code is assuming the query succeeded and attempts to fetch a row from that false value, which is not a valid result handle. It is bad practice to assume a query will succeed. Even if the query string is syntactically valid, there's many many many other ways failure can occur, and you should check for success (or failure) at every step.