下面的代码(search.php)仅适用于分页的第一页,但是当我单击第二页时,它显示以下错误。
“注意:未定义的索引:在第15行的/opt/lampp/htdocs/testdb/search.php中搜索” **。
我也尝试使用$ _SESSION,但是它不起作用。该查询仅针对分页的第一页传递。我是编码的初学者。任何帮助或建议将非常有帮助。谢谢。
<?php
//Database connection
$mysqli = NEW MySQLi('localhost','root','','dbname');
//POST data from the query search page which is to be fetched from Database
$a=$_POST['search'];// this is line 15 of my code for which the error is appearing
//PAGINATION
$rpp = 25; //records per page
isset($_GET['page']) ? $page = $_GET['page'] : $page = 0;
if($page > 1) {
$start = ($page * $rpp) - $rpp;
}
else {
$start = 0;
}
//SQL query
$res =$mysqli->query("SELECT * FROM t1 WHERE col4 like '$a'");
$num = $res->num_rows;
$totalpages = $num / $rpp;
echo $totalpages; //to check the no. of total pages and if it is not whole no. then in the for loop at the end of the code add +1 with $totalpages (i.e. for($x = 1; $x <= $totalpages + 1; $x++))
$res = $mysqli->query("SELECT * FROM t1 WHERE col4 like '$a' LIMIT $start, $rpp");
//Fetch data from table "<table>";
echo "<table>";
while($rows = $res->fetch_assoc()){
$a = $rows['col1'];
$b = $rows['col2'];
$c = $rows['col3'];
$d = $rows['col4'];
echo "<tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td></tr>";
}
echo "</table><p />";
echo "<div class='pagination'>";
//make link for next page in pagination
for($x = 1; $x <= $totalpages; $x++)
{
echo "<a href='?page=$x'>$x</a>";
}
?>
<!--Below is the HTML code for the search engine:-->
<html>
<body>
<h2>Search page</h2>
<form action='search.php' method='POST'>
<input type='text' name='search'></br></br>
<input type='submit' name='submit' value='Submit'> </br>
</form>
</body>
</html>
<!--My data has only four columns-->
<!--sample dataset-->
PtRNAome_1 nuclear GCA_000001735.2 Arabidopsis thaliana : nuclear
PtRNAome_2 nuclear GCA_000001735.2 Arabidopsis thaliana : nuclear
PtRNAome_3 nuclear GCA_000001735.2 Arabidopsis thaliana : nuclear
PtRNAome_4 nuclear GCA_000001735.2 Arabidopsis thaliana : nuclear
PtRNAome_5 nuclear GCA_000001735.2 Arabidopsis thaliana : nuclear