简体   繁体   English

搜索引擎/分页

[英]Search Engine/Pagination

im trying to make a search engine but i Got this error 我试图做一个搜索引擎,但我遇到了这个错误

Notice: Undefined variable: construct in C:\xampp\htdocs\test\search.php on line 24. 

im trying to display the results and show the pagination. 我试图显示结果并显示分页。

Here's my code: 这是我的代码:

<?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)

i dont know why is it undefined. 我不知道为什么它没有定义。

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

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

}

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

Thanks. 谢谢。

You're getting that warning because you are using .= which is used to append. 之所以收到该警告,是因为您使用的是.= (用于附加)。

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

You haven't defined $construct previously but you are trying to append a string to it, hence the warning. 您之前没有定义$construct但是您尝试向其附加字符串,因此出现警告。 You should define $construct before you use it. 您应该在使用$construct之前对其进行定义。 For example: 例如:

<?php

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM