How can I make <a href> submit a $_GET

Status
Not open for further replies.

Mikee

Active Member
Jul 8, 2017
162
102
I have a set of links as seen here
EEurvXS.png

I want to make it so when you click on it it sends a GET request and then I'll be able to organize the articles/blog posts by GET request. i.e. technology will only sort the technology tagged articles.

But i don't know how to make the <a href> links submit GET
Code:
<div class="lx-sidebar-item">
                                <div class="lx-sidebar-item-title">
                                    <h3>Categories</h3>
                                </div>
                                <form method = "GET">
                                <div class="lx-sidebar-item-content">
                                    <div class="lx-links-list">
                                        <ul>
                                        <?php $i = 0; while ($i < $numOfRowsCategories){
                                            echo '
                                          <form action="" method="post">                                      
                                            <li><a href="?category=">';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>

Here is my code so far for the sidebar. The PHP stuff gets pulled from another file that has an array[] of categories, and the rowCount.
 
Last edited by a moderator:

MayoMayn

BestDev
Oct 18, 2016
1,423
683

Simply style a submit button to look like an a element

Also I don't get what you trynna achieve this way
 

Mikee

Active Member
Jul 8, 2017
162
102

Simply style a submit button to look like an a element

Also I don't get what you trynna achieve this way
I want my articles in the center that you see to be organized by category. When you load the website it loads all of the articles by latest date. then if you click "music" it'll reload the page and only show articles that are under "music" category. Just a filter type thing.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
I want my articles in the center that you see to be organized by category. When you load the website it loads all of the articles by latest date. then if you click "music" it'll reload the page and only show articles that are under "music" category. Just a filter type thing.
I get what you want, but I'm curious why you don't use a frontend framework? Suits better

Sent from my SM-G955F using Tapatalk
 

Mikee

Active Member
Jul 8, 2017
162
102
I get what you want, but I'm curious why you don't use a frontend framework? Suits better

Sent from my SM-G955F using Tapatalk
I wouldn't know where to begin/what to look into :p webdev is a new beast that i'm only starting to learn.
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Probably is, in industry they would fire you for this. Making a database request for each sortment takes way too many resources. You put it into a table.
 

Mikee

Active Member
Jul 8, 2017
162
102
Probably is, in industry they would fire you for this. Making a database request for each sortment takes way too many resources. You put it into a table.
Code:
$database = DBConnect::EstablishConnect();
$query = $database->prepare("SELECT * FROM categories");
$query->execute();

$numOfRowsCategories = $query->rowCount();
$CategoriesResult = $query->fetchAll(PDO::FETCH_ASSOC);
$categories = [];
$amount = [];
foreach ($CategoriesResult as $data){
    array_push($categories, $data['category']);
    array_push($amount, $data['amount']);
}

The data is pulled once and stored into an array. the code in my first post literally just goes through the array and prints them off. Not making a request each time. User enters website, array is populated, then it's passed along.
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Code:
$database = DBConnect::EstablishConnect();
$query = $database->prepare("SELECT * FROM categories");
$query->execute();

$numOfRowsCategories = $query->rowCount();
$CategoriesResult = $query->fetchAll(PDO::FETCH_ASSOC);
$categories = [];
$amount = [];
foreach ($CategoriesResult as $data){
    array_push($categories, $data['category']);
    array_push($amount, $data['amount']);
}

The data is pulled once and stored into an array. the code in my first post literally just goes through the array and prints them off. Not making a request each time. User enters website, array is populated, then it's passed along.
Right but if you're using a GET request and you're reloading the page , then aren't you repopulating that array?
 
Here is a great example
 

Mikee

Active Member
Jul 8, 2017
162
102
The solution was simple.
jut concat the name of the category i want to GET with ?category=

Code:
 <ul>
   <?php $i = 0; while ($i < $numOfRowsCategories){
        echo '<li><a href="?category='.$categories[0].'">'; echo $categories[0]; array_shift($categories); echo'<span>';echo $amount[0]; array_shift($amount);'</span></a></li>';$i++;}
    ?>
  </ul>

Ty @TesoMayn for help in the sb
 
Status
Not open for further replies.

Users who are viewing this thread

Top