搜索引擎/分页



我试图做一个搜索引擎,但我得到了这个错误

Notice: Undefined variable: construct in C:xampphtdocstestsearch.php on line 24. 

我正在尝试显示结果并显示分页。

下面是我的代码:

<?php
$button = $_GET ['submit'];
$search = $_GET ['search']; 
$x = 0;
if(!$button)
echo "you didn't submit a keyword";
else
{
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","root","test");
mysql_select_db("test");
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)

我不知道为什么它是undefined

这是我的第24行:$construct .= " username LIKE '%$search_each%'";
else
$construct .= " AND details_in LIKE '%$search_each%'";
}
$construct ="SELECT * FROM intime WHERE $construct";
$run = mysql_query($construct);

谢谢。

你会得到这个警告,因为你正在使用.=,这是用来追加的

$construct .= " username LIKE '%$search_each%'";

您之前没有定义$construct,但您试图将字符串附加到它,因此出现警告。您应该在使用$construct之前定义它。例如:

<?php
$button = $_GET ['submit'];
$search = $_GET ['search']; 
$x = 0;
$construct = ''; // Defined construct here
//
// .. rest of your code
//

最新更新