我正在尝试制作一个搜索引擎,但我遇到了这个错误
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);
谢谢。
最佳答案
您收到该警告是因为您正在使用用于追加的 .=
。
$construct .= " username LIKE '%$search_each%'";
您之前没有定义 $construct
但您正试图向其附加一个字符串,因此出现了警告。您应该在使用之前定义 $construct
。例如:
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
$x = 0;
$construct = ''; // Defined construct here
//
// .. rest of your code
//
关于php - 搜索引擎/分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25470768/