简体   繁体   English

如何将GET添加到<a href>标签?</a>

[英]How do I add a GET to an <a href> tag?

https://imgur.com/a/HUX8Z https://imgur.com/a/HUX8Z

As seen in the image, I have a set of categories. 如图所示,我有一组类别。 I want, when I click on a category, it reorganizes the blog posts by category. 我想要,当我单击类别时,它会按类别重新组织博客文章。 In order to do this I need to send a GET on the side. 为此,我需要在侧面发送GET。 But I can't figure it out. 但我不知道。

<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>

The numOfRowsCategoriesis just a rowCount of the cateogires table in the database. numOfRowsCategories只是数据库中cateogires表的rowCount。 and the $categories is just an array from the database of all categories. $ categories只是来自所有类别数据库的数组。

i tried this solution, which said to use buttons instead How can I submit a POST form using the <a href="..."> tag? 我尝试了该解决方案,该解决方案说使用按钮代替, 如何使用<a href="...">标记提交POST表单?

Although it works in theory, I can't figure out how to style the button to make it look like my current page. 尽管从理论上讲它是可行的,但我不知道如何设置按钮的样式以使其看起来像我的当前页面。

if $categories[0] is Id. 如果$ categories [0]是ID。 you should use 你应该使用

  <ul>
    <?php $i = 0; while ($i < $numOfRowsCategories){
        echo '<li><a href="yourPage.php?categories='.$categories[$i].'">Category N</a></li>';$i++;}
    ?>
  </ul>

here's yourPage.php is the page which will get $_GET['categories'] on the otherside. 这是yourPage.php是将在另一侧获得$ _GET ['categories']的页面。 And, ?categories= is variable which will be send to yourPage.php by GET Method. 并且,?categories =是变量,它将通过GET方法发送到yourPage.php。

You'll need to change the a tag to be: 您需要将标签更改为:

<a href="ajax_url_goes_here?var_name_expected_on_server=category_id">

If you provide more information I can offer a more complete answer. 如果您提供更多信息,我可以提供更完整的答案。 Right now it's unclear if $categories contains the ids or not and what the name of the variable is that your server side code is expecting. 现在还不清楚$ categories是否包含id,以及服务器端代码期望的变量名称是什么。

<ul>
<?php $i = 0; while ($i < $numOfRowsCategories){
    echo '<li><a href="yourPage.php?categories='.$categories[$i].'">Category N</a></li>';$i++;}
?>

is the correct code. 是正确的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM