由于警告,带有分页(使用Php)的Php搜索代码未生成导航链接。如何更正错误?
我是php编程新手,我已经编写了php代码从数据库中搜索数据,然后用分页链接显示数据,以便在搜索结果过多的情况下轻松导航。但是由于上述警告,分页链接将不会显示。查询没有生成计数结果以使my$limit变量为true,从而仅显示第一页。这是下面的代码,请您帮我更正错误,以便显示分页链接由于警告,带有分页(使用Php)的Php搜索代码未生成导航链接。如何更正错误?,php,mysql,pagination,Php,Mysql,Pagination,我是php编程新手,我已经编写了php代码从数据库中搜索数据,然后用分页链接显示数据,以便在搜索结果过多的情况下轻松导航。但是由于上述警告,分页链接将不会显示。查询没有生成计数结果以使my$limit变量为true,从而仅显示第一页。这是下面的代码,请您帮我更正错误,以便显示分页链接 <?php include_once("dbconnect.php"); if(isset($_GET["search"])) {
<?php
include_once("dbconnect.php");
if(isset($_GET["search"]))
{
$condition = '';
$search_query = explode(" ", $_GET["search"]);
foreach($search_query as $text)
{
$condition .= "search LIKE '%".mysqli_real_escape_string($dbconnect, $text)."%' OR ";
}
$sql = "SELECT COUNT(stockID) FROM stock WHERE search LIKE ". $condition ."GROUP BY stockID";
$query = mysqli_query($dbconnect, $sql);
$row = mysqli_fetch_row($query);
$rows = $row[0];
$page_rows = 12;
$last = ceil($rows/$page_rows);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$condition = '';
$search_query = explode(" ", $_GET["search"]);
foreach($search_query as $text)
{
$condition .= "search LIKE
'%".mysqli_real_escape_string($dbconnect, $text)."%' OR ";
}
$condition = substr($condition, 0, -4);
$sql= "SELECT * FROM stock WHERE " . $condition."
ORDER BY stockID ASC $limit";
$query = mysqli_query($dbconnect, $sql);
$textline1 = "(<b>$rows</b>)";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
$paginationCtrls = '';
$search_query = $_GET['search'];
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?
pn='.$previous.'&search='.$search_query.'">Previous</a> ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?
pn='.$i.'">'.$i.'</a> ';
}
}
}
$paginationCtrls .= ''.$pagenum.' ';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?
pn='.$i.'&search='.$search_query.'">'.$i.'</a> ';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'.$_SERVER['PHP_SELF'].'?
pn='.$next.'&search='.$search_query.'">Next</a> ';
}
}
$list = '';
$lists = '';
while($row = mysqli_fetch_array($query)){
$id = $row["stockID"];
$name = $row["stockName"];
$image = $row["thumbnail"];
$description = $row["description"];
$topline = $row['topline'];
$lists .= '<div class="col-md-3" style="margin-bottom:10px;">
<div class="panel panel-info"><a href="index.php?
page=item&stockID='.$id.'&sub_category=">
<div class="panel-body">
<img class="img-responsive" style="height:100px;"
src="resources/stocks_images/'.$image.'" />
</div>
<div class="panel-footer" style="height:100px;">'.$name.'
</div></a>
</div>
</div>';
}
}
mysqli_close($dbconnect);
?>
$dbconnect
在脚本中未定义。还要重写您的查询:
$sql=“从类似搜索的股票中选择COUNT(stockID)”$条件:“按stockID分组”代码>我在“分组依据”之前添加了一个空格。希望这会有所帮助。它产生了这个错误-->>警告:mysqli_fetch_row()希望参数1是mysqli_result,在第17行的C:\xampp\htdocs\HTML\searchresult.php中给出的布尔值,$dbconnect变量是定义的,因为当我搜索结果时,而不是分页链接时,你仍然会得到警告吗?(添加空格后?)