0

https://i.stack.imgur.com/IUy2H.jpg

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. 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. and the $categories is just an array from the database of all categories.

i tried this solution, which said to use buttons instead How can I submit a POST form using the <a href="..."> tag?

Although it works in theory, I can't figure out how to style the button to make it look like my current page.

Cristophs0n
  • 1,246
  • 3
  • 19
  • 27

3 Answers3

2

if $categories[0] is 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. And, ?categories= is variable which will be send to yourPage.php by GET Method.

Kashif Saleem
  • 132
  • 2
  • 12
0

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.

dukedevil294
  • 1,285
  • 17
  • 31
0
<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.