如图所示,我有一组类别。我想,当我点击一个类别时,它会按类别重新组织博客文章。为此,我需要在旁边发送一个 GET。但我想不通。
<div class="lx-sidebar-item">
<div class="lx-sidebar-item-title">
<h3>Categories</h3>
</div>
<div class="lx-sidebar-item-content">
<div class="lx-links-list">
<ul>
<?php $i = 0; while ($i < $numOfRowsCategories){
echo '<li><a href="">';echo $categories[0]; array_shift($categories); echo'<span>';echo $amount[0]; array_shift($amount);'</span></a></li>';$i++;}
?>
</ul>
</form>
<div class="lx-clear-fix"></div>
</div>
</div>
</div>
numOfRowsCategories 只是数据库中 cateogires 表的行计数。 $categories 只是来自所有类别数据库的数组。
我试过这个解决方案,它说使用按钮代替 How can I submit a POST form using the <a href="..."> tag?
虽然它在理论上可行,但我不知道如何设置按钮的样式以使其看起来像我当前的页面。
最佳答案
如果 $categories[0] 是 Id。你应该使用
<ul>
<?php $i = 0; while ($i < $numOfRowsCategories){
echo '<li><a href="yourPage.php?categories='.$categories[$i].'">Category N</a></li>';$i++;}
?>
</ul>
这里是 yourPage.php 是将在另一侧获得 $_GET['categories'] 的页面。并且,?categories= 是变量,它将通过 GET 方法发送到 yourPage.php。
关于php - 如何将 GET 添加到 <a href> 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48874817/