搜索它的全部工作状态,但是当我试图找到一个单词时,“让我们.找不到it...the错误是warning...Warning: mysql_num_rows()希望参数1是资源,在我的文件中给出第73行的布尔值”。有人能找到问题或者让我的代码来处理这个词吗..。
代码:
$search = $_GET ['search'];
mysql_connect("localhost","root","");
mysql_select_db("search");
$search_exploded = explode (" ", $search);
$x = "";
$construct = "";
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="title LIKE '%$search_each%' OR type LIKE '%$search_each%' OR year LIKE '%$search_each%'";
else
$construct .="AND title LIKE '%$search_each%' OR type LIKE '%$search_each%' OR year LIKE '%$search_each%'";
}
$constructs ="SELECT * FROM search WHERE $construct";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "
<header class='page-header'>
<h1 class='page-title'>Nothing Found</h1>
</header>
<div class='page-content'>
<p style='color:#999;'>Sorry, but nothing matched your search terms. Please try again with some different keywords.</p>
<aside id='search-2' class='widget widget_search'>
<form role='search' method='get' class='search-form' action='s'>
<label>
<input autocomplete='off' type='search' class='search-field' placeholder='Search Again …' value='' name='search' title='Search for:'>
</label>
<input type='submit' class='search-submit' value='Search'>
</form>
</aside>
</div></div>
";
else
{
echo"
<header class='page-header'>
<h1 class='page-title'>Search results for <b>'$search'</b></h1>
</header>
";发布于 2015-01-16 15:13:27
连接查询之间缺少空格,MySQL将其解读为:
$constructs ="SELECT * FROM search WHERE $constructtitle LIKE '%$search_each%'";注意$construct和title是如何捆绑在一起的,就像其他查询一样?
将$search = $_GET ['search'];更改为:
$search = stripslashes($_GET ['search']);
$search = mysql_real_escape_string($_GET ['search']);为了接受撇号。
还将$construct .="title LIKE更改为$construct .=" title LIKE
和$construct .="AND title LIKE到$construct .=" AND title LIKE
更改您的$run = mysql_query($constructs);
到$run = mysql_query($constructs) or die(mysql_error());,以便发现错误。
https://stackoverflow.com/questions/27985646
复制相似问题