这个问题对某些人来说是一个简单的问题,但我不明白我需要做什么来解决这个问题。
我有一个显示分页表的网页。表格上方是会话从前一页传递的一些信息,用户从下拉菜单中选择了一个选项。
当用户分页到第二页等时,传递的信息会丢失,可能会刷新页面。
我已经搜索并观看了许多关于 Ajax、jquery 和 php 等的教程(超过 20 个),但我无法理解我在看什么。虽然我遵循教程,但我无法解释可以解决我的问题的教程。
我想一步一步的指南将是解决这个问题的唯一方法,而不是让别人为我做这件事。
我绝对会感谢在这件事上的任何帮助。
我试图传递到分页及以后的第二页的代码是变量 $brandname
, $picked
, $pickchek
。下面列出了代码的 php 部分。
echo "<div id=firstpick>";
$brandname = $_GET['brandname'];
$picked = $_GET['picked'];
$pickcheck = $_GET['pickcheck'];
$brands =($brandname);
$_SESSION['$brandname']= $brandname;
$pick =($picked);
$_SESSION['$picked']= $pick;
$picker =($pickcheck);
$_SESSION['$pickcheck']=$picker;
echo "</div>";
$tbl_name="pickme";
$adjacents = 3;
$query = "SELECT COUNT(*) as num FROM tirestock";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages["num"];
$targetpage = "connecttest.php"; //your file name (the name of this file)
$limit = 5; //how many items to show per page
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$page=mysql_real_escape_string($page);
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0;
$sql = "SELECT * FROM tirestock LIMIT $start, $limit";
$result = mysql_query($sql);
if ($page == 0) $page = 1; /if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit);//lastpage is = total pages / items per
$lpm1 = $lastpage - 1; //last page minus 1
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
else
$pagination.= "<span class=\"disabled\">« previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2))//not enough pages to bother breaking
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span
class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?
page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2);
$counter++)
{
if ($counter == $page)
$pagination.= "<span
class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?
page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?
page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?
page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
else
$pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
echo "<div style='font-weight:bold' text-align:center;><font size='5'>You picked Brand:
$brandname<br></br></hr></div>";
echo "<div style='font-weight:bold'><font size='5'>You picked Size: $picked<br></br></hr>
</div>";
echo "<div style='font-weight:bold'><font size='5'>You picked Type: $pickcheck<br></br>
</hr></div>";