我的脚本代码搜索与分页,工作!但是当我单击下一页时,服务器会写入此错误:
注意:未定义索引:第 129 行 C:\xampp\htdocs\php\search.php 中的 byidaifa
注意:未定义的索引:第 147 行 C:\xampp\htdocs\php\search.php 中的 byidaifa
注意:未定义索引:第 187 行 C:\xampp\htdocs\php\search.php 中的 byidaifa
“byidaifa”是 mysql 中 IDAIFA 上的 INT 数字。似乎它必须保持为空!
错误在哪里?
非常感谢!
<?php
include('conn.php');
session_start();
$_SESSION['byidaifa']=$_REQUEST['byidaifa'];
$_SESSION['bynome']=$_REQUEST ['bynome'];
$_SESSION['bycognome']=$_REQUEST ['bycognome'];
$_SESSION['bytipologia']=$_REQUEST ['bytipologia'];
$_SESSION['bymarca']=$_REQUEST ['bymarca'];
$_SESSION['bymodello']=$_REQUEST ['bymodello'];
$_SESSION['bystato']=$_REQUEST ['bystato'];
$_SESSION['bysoftware']=$_REQUEST ['bysoftware'];
$limit = 50;
$count = "SELECT COUNT(*) as num FROM asset WHERE ID ";
if($_REQUEST['byidaifa'])
$count = $count . " AND IDAIFA LIKE '".$_SESSION['byidaifa']."' ";
if($_REQUEST ['bynome'])
$count = $count . " AND Nome LIKE '".$_SESSION['bynome']."' ";
if($_REQUEST ['bycognome'])
$count = $count . " AND Cognome LIKE '".$_SESSION['bycognome']."' ";
if($_REQUEST ['bytipologia'])
$count = $count . " AND Tipologia LIKE '".$_SESSION['bytipologia']."' ";
if($_REQUEST ['bymarca'])
$count = $count . " AND Marca LIKE '".$_SESSION['bymarca']."' ";
if($_REQUEST ['bymodello'])
$count = $count . " AND Modello LIKE '".$_SESSION['bymodello']."' ";
if($_REQUEST ['bystato'])
$count = $count . " AND Stato LIKE '".$_SESSION['bystato']."' ";
if($_REQUEST ['bysoftware'])
$count = $count . " AND Software LIKE '".$_SESSION['bysoftware']."' ";
$resultcount = mysql_query($count);
$total_pages = mysql_fetch_array(mysql_query($count));
$total_pages = $total_pages['num'];
$stages = 3;
$page = isset($_GET['page']) ? mysql_real_escape_string($_GET['page']) : 0;
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
$querysearch = "SELECT * FROM asset WHERE ID ";
if($_REQUEST['byidaifa'])
$querysearch = $querysearch . " AND IDAIFA LIKE '".$_SESSION['byidaifa']."' ";
if($_REQUEST ['bynome'])
$querysearch = $querysearch . " AND Nome LIKE '".$_SESSION['bynome']."' ";
if($_REQUEST ['bycognome'])
$querysearch = $querysearch . " AND Cognome LIKE '".$_SESSION['bycognome']."' ";
if($_REQUEST ['bytipologia'])
$querysearch = $querysearch . " AND Tipologia LIKE '".$_SESSION['bytipologia']."' ";
if($_REQUEST ['bymarca'])
$querysearch = $querysearch . " AND Marca LIKE '".$_SESSION['bymarca']."' ";
if($_REQUEST ['bymodello'])
$querysearch = $querysearch . " AND Modello LIKE '".$_SESSION['bymodello']."' ";
if($_REQUEST ['bystato'])
$querysearch = $querysearch . " AND Stato LIKE '".$_SESSION['bystato']."' ";
if($_REQUEST ['bysoftware']){
$querysearch = $querysearch . " AND Software LIKE '".$_SESSION['bysoftware']."' ";
}
$querysearch = $querysearch . " LIMIT $start, $limit ";
$resultsearch = mysql_query($querysearch);
if(isset($_REQUEST))
{
unset($_REQUEST['page']);
$querysearch = http_build_query($_REQUEST);
}
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$prev'>Prev</a> ";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2))
{
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$lastpage'>$lastpage</a>";
}
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=1'>1</a>";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$lastpage'>$lastpage</a>";
}
else
{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=1'>1</a>";
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='search.php?search=$querysearch&submit=Go&page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
echo $total_pages.' Results';
// pagination
echo "<table border='1' style='margin:0 auto;'>";
echo "<tr>",
"<td colspan='3'> Azioni </td> <td> Nome </td> <td> Cognome </td> <td> IDAIFA </td> <td> Utilizzo</td> <td> Tipologia</td> <td>Marca</td> <td>Modello</td> <td>Stato</td>",
"</tr> \n";
if ($resultsearch)
while($dati = mysql_fetch_assoc($resultsearch))
{
echo "<tr>";
echo "<td> <a href='detailasset.php?ID=$dati[ID]'><img src='../images/eye.png'></a> </td>";
echo "<td> <a href='modasset.php?ID=$dati[ID]'><img src='../images/edit.png'></a> </a> </td>";
echo "<td> <a href='deleteasset.php?ID=$dati[ID]?confirm=true' class='confirm'> <img src='../images/delete.png'></a></td>";
print "<td> $dati[Nome] </td>";
print "<td> $dati[Cognome] </td>";
print "<td> $dati[IDAIFA] </td>";
print "<td> $dati[Utilizzo] </td>";
print "<td> $dati[Tipologia] </td>";
print "<td> $dati[Marca] </td>";
print "<td> $dati[Modello] </td>";
print "<td> $dati[Stato] </td>";
print "<td> $dati[Software] </td>";
echo "</tr> \n";
}
echo "</table></div>\n";
echo $paginate;
?>