搜索引擎/分页

时间:2014-08-24 10:32:45

标签: php mysql phpmyadmin

即时尝试制作搜索引擎,但我收到此错误

Notice: Undefined variable: construct in C:\xampp\htdocs\test\search.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)

我不知道为什么它没有定义。

这是我的第24行:$construct .= " username LIKE '%$search_each%'";

else
$construct .= " AND details_in LIKE '%$search_each%'";

}

$construct ="SELECT * FROM intime WHERE $construct";
$run = mysql_query($construct);

感谢。

1 个答案:

答案 0 :(得分:0)

您正在收到该警告,因为您使用的是用于附加的.=

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

您之前没有定义过$construct,但是您正在尝试为其添加字符串,因此会出现警告。您应该在使用之前定义$construct。例如:

<?php

$button = $_GET ['submit'];
$search = $_GET ['search']; 
$x = 0;
$construct = ''; // Defined construct here

//
// .. rest of your code
//