从分页搜索链接到mysql单个记录

问题描述 投票:1回答:1

我试图通过我的搜索使用php / ajax_pagination链接到我的mysql数据库中的单行记录信息,我试图开始工作的代码是:

<div id="posts_content">
<?php
//Include pagination class file
include('Pagination.php');

//Include database configuration file
include('dbConfig.php');

$limit = 3;

//get number of rows
$queryNum = $db->query("SELECT COUNT(*) as postNum FROM posts");
$resultNum = $queryNum->fetch_assoc();
$rowCount = $resultNum['postNum'];

//initialize pagination class
$pagConfig = array(
    'totalRows' => $rowCount,
    'perPage' => $limit,
    'link_func' => 'searchFilter'
);
$pagination =  new Pagination($pagConfig);

//get rows
$query = $db->query("SELECT * FROM posts ORDER BY id DESC LIMIT $limit");

if($query->num_rows > 0){ ?>
    <div class="posts_list">
    <?php
        while($row = $query->fetch_assoc()){ 
            $postID = $row['id'];
    ?>
        <div class="list_item"><a href="file.php?id="'.$row['id'].'"><h2><?php echo $row["title"]; ?></h2></a></div>
    <?php } ?>
    </div>
    <?php echo $pagination->createLinks(); ?>
<?php } ?>
</div>

我的href链接显然有问题:

<a href="file.php?id="'.$row['id'].'"><h2><?php echo    $row["title"]; ?></h2></a>

或者我的file.php页面:

  <?php 


 // GET ID FROM THE URL
 $id = $_GET['id'];

  ?>

<!DOCTYPE HTML>
<html lang="en">
<head>
  <title>Ajax Pagination with Search and Filter in PHP</title>
 <link href='style.css' rel='stylesheet' type='text/css'>
<script src="jquery.min.js"></script>
 <script type="text/javascript"></script>
</head>
<body>


<?php 

$sql =mysql_query("select * from posts where id='".$id."'");
    while($row = mysql_fetch_array($sql)){
?>
    <tr>
        <th>title:</th>
        <th>created:</th>
        <th>modified:</th>
        <th>statusr:</th>
    </tr>
    <tr>
        <td><?=$row['title']?></td>
        <td><?=$row['created']?></td>
        <td><?=$row['modified']?></td>
        <td><?=$row['status']?></td>
    </tr>
<?php 
    }
?>

但是我无法理解为什么其他一切似乎工作得很好,也许我一直在看这个很长时间并错过了一些明显的东西...但是任何帮助都会非常感激。

php ajax pagination
1个回答
0
投票

使用以下代码:

<div class="list_item"><a href="file.php?id="<?php echo $row['id'] ?>"><h2><?php echo $row["title"]; ?></h2></a></div>
© www.soinside.com 2019 - 2024. All rights reserved.