gpt4 book ai didi

php - 分页工作正常但出现错误

转载 作者:行者123 更新时间:2023-11-30 01:11:33 25 4
gpt4 key购买 nike

我的脚本代码搜索分页,工作!但是当我单击下一页时,服务器会写入以下错误:

Notice: Undefined index: byidaifa in C:\xampp\htdocs\php\search.php on line 129

Notice: Undefined index: byidaifa in C:\xampp\htdocs\php\search.php on line 147

Notice: Undefined index: byidaifa in C:\xampp\htdocs\php\search.php on line 187

“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;
?>

最佳答案

如果您不确定变量是否会被设置,请在调用之前检查它是否已设置,例如:

if(isset($_REQUEST['byidaifa']){
$_SESSION['byidaifa']=$_REQUEST['byidaifa'];
}
else{
$_SESSION['byidaifa'] = '';
}

关于php - 分页工作正常但出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19435684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com