如何在使用分页时使用PHP中的Session传输GET / POST数据

如何在使用分页时使用PHP中的Session传输GET / POST数据

问题描述:

This is my code:

$tag1 = $_GET['tag1'];
$tag2 = $_GET['tag2'];

$stmt = $conn->prepare("SELECT name FROM info WHERE tag1='$tag1' OR tag2='$tag2' LIMIT $limit OFFSET $start");

// Pagination
while ($pagenumber != $totalpages) 
    {
    ++$pagenumber;

    echo "<a href='?page=".$pagenumber."'>".$pagenumber."</a>";  
    }

Everything is working fine, but when i go to any other page, I get this 2 errors:

Notice: Undefined index: tag1

Notice: Undefined index: tag2

这是我的代码: p>

  $ tag1 = $ _GET  ['tag1']; 
 $ tag2 = $ _GET ['tag2']; 
 
 $ stmt = $ conn-&gt; prepare(“SELECT name FROM info WHERE tag1 ='$ tag1'OR tag2 ='$  tag2'LIMIT $ limit OFFSET $ start“); 
 
 //分页
while($ pagenumber!= $ totalpages)
 {
 ++ $ pagenumber; 
 
 echo”&lt; a href ='  ?页=”。$页面编号。 “'&gt;” 中$页面编号。 “&LT; / A&gt;” 中;  
} 
  code>  pre> 
 
 

一切正常,但当我去任何其他页面时,我得到了这两个错误: p>

 注意:未定义索引:tag1 
 
注意:未定义索引:tag2 
  code>  pre> 
  div>

you can pass your get value into your link, be sure that vars are set before

try this please

echo "<a href='?page=".$pagenumber."&tag1=".$tag1."&tag2=".$tag2."'>".$pagenumber."</a>";