【问题标题】:How to create pagination with if isset submit button如何使用 ifisset 提交按钮创建分页
【发布时间】:2018-05-24 06:22:27
【问题描述】:

如何使用if(isset($_POST['submit'])){创建分页

第一次显示时一切正常,但是当我在分页中单击下一页时,它会显示如下错误:

Notice: Undefined variable: modesearch in C:\xampp\htdocs\KaRomAshi\search.php on line 21 Notice: Undefined variable: searchstring in C:\xampp\htdocs\KaRomAshi\search.php on line 21 Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIKE '%%'' at line 1 in C:\xampp\htdocs\KaRomAshi\search.php:23 Stack trace: #0 C:\xampp\htdocs\KaRomAshi\search.php(23): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\KaRomAshi\search.php on line 23

我的 isset 和分页代码在这里

if(isset($_POST['submit'])){
$modesearch = htmlentities($_POST['modesearch']);
$searchstring = htmlentities($_POST['searchstring']);
}
/*pagination code here*/
$limit = 1;
$query = ("SELECT * FROM post where $modesearch LIKE '%$searchstring%'");
$s = $db->prepare($query);
$s->execute();
$total_results = $s->rowCount();
$total_pages = ceil($total_results/$limit);
if (!isset($_GET['page'])) {
$page = 1;
} else{
$page = $_GET['page'];
}
$starting_limit = ($page-1)*$limit;
$show  = "SELECT * FROM post where $modesearch LIKE '%$searchstring%' ORDER BY date DESC LIMIT $starting_limit, $limit";
$r = $db->prepare($show);
$r->execute(); 
?>

此处显示数据的代码

<?php while ($value = $r->fetch(PDO::FETCH_ASSOC)): ?>
<!-- Start Main Posting Here -->
<article class="list-lyrics">
<h3 class="newupdate"><a href="lyric.php?idp=<?php echo $value['idpost'] ?>&link=<?php echo ($value['artis']); ?>-<?php echo ($value['title']); ?>"><?php echo html_entity_decode($value['title']); ?></a></h3>
<div class="artis-home">
<p class="general"><i class="fa fa-user-o" aria-hidden="true"></i> <a href="artis.php?ida=<?php echo $value['idpost'] ?>&link=<?php echo ($value['artis']); ?>"><?php echo html_entity_decode ($value['artis']); ?></a></p>
</div>
</article>
<?php endwhile; } ?>

还有我的基于分页的引导程序

<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="archives.php" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
<?php for ($page=1; $page <= $total_pages ; $page++):?>
<li class="page-item active">

</li>
<li class="page-item">
<a href='<?php echo "?page=$page"; ?>' class="links"><?php  echo $page; ?></a>
</li>
<?php endfor; ?> 
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav> 

【问题讨论】:

    标签: php mysql twitter-bootstrap pagination


    【解决方案1】:

    您必须将搜索词附加到分页链接,但为此您必须更改代码以通过 GET 变量接受搜索词,或者分页应该基于在表单上执行 POST 工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 2015-04-08
      • 2023-03-10
      相关资源
      最近更新 更多