1

我们使用了分页 123 按钮,这里如果我们单击下一步按钮也意味着它应该转到下一页。但是在这里它不会转到下一页,因为这里我将 sql 查询中的 _POST 变量传递给 where 条件,所以如果单击下一页它不会显示相关页面。我们认为点击其他页面后 POST 变量值不会更新。这是我的代码。提前致谢。

if(isset($_POST['submit']))
 {
  $bool = true;     
  $gender=$_POST['gender'];      
 } 

 if(($bool == true) 
 {

   $bool1=true;
   $connection = mysql_connect("localhost","root","Sakthi");      
  if (!$connection)
  {
   die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("nursingcarein",$connection);

  if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
  $start_from = ($page-1) * 3;

  $gender1=$gender;
  $profession1=$profession;
  $state1=$state;

  /**** Here gender value doesnt update when click the next page i think we have a error in this query ****/      
  $sql = "SELECT id,description,name FROM nursereg WHERE gender='$gender1' LIMIT     $start_from, 3";

  $rs_result = mysql_query ($sql,$connection);
  echo "<table>
  <tr><td>Image</td><td>Description</td></tr>";
   while($row=mysql_fetch_array($rs_result)) {
    echo" <tr>";
        echo"<td>"; echo "<img src='image1.php?id=".$row['id']."'>"; echo"</td>";
        echo"<td>"; echo  $row['name']; echo"</td>";
        echo"<td>"; echo  $row['description']; echo"</td>";
        echo"</tr>";
     };
  echo"</table>"; 
  $sql = "SELECT COUNT(Name) FROM nursereg";
 $rs_result = mysql_query($sql,$connection);
  $row = mysql_fetch_row($rs_result);
  $total_records = $row[0];
  $total_pages = ceil($total_records / 5);    
 for ($i=1; $i<=$total_pages; $i++) {
   $pageno = $i;
       echo "<a href='index2.php?page=".$i."'>".$i."</a> ";   
     };
 };

 ?>
4

1 回答 1

0

您的分页使用 href,这不会像您的代码建议的那样调用 POST

$gender1=$_POST['gender'];

尝试将性别添加到分页并通过 GET 获取

echo "<a href=\"index2.php?page=$i&gender=$gender1\">".$i."</a> "; 

然后在你的代码中

$gender1 = isset($_POST['gender']) ? $_POST['gender'] : $_GET['gender'];
于 2013-03-15T15:58:28.640 回答