I have some code that looks like this:
<div class="container">
<aside class="sidebar">
<a href="index.php?Cat=members"><h3>Members</h3></a>
<a href="index.php?Cat=prodcat"><h3>Product Categories</h3></a>
</aside>
<article class="content">
<section>
<?php
echo $_GET["Cat"];
if ($_GET["Cat"] = 'members'){
$membership = New Membership();
$membership->member_List($sort);
}
else if ($_GET["Cat"] = 'prodcat'){
$membership = New Membership();
$membership->prodcat_List();
}
else {
echo 'Welcome';
}
?>
</section>
</article>
</div>
What should happen, is that when the link Members is pressed. The page should reload itself and show only what is brought back from the member_list.
Or if the product categories link is then pressed – it should then show whatever comes back from prodcat_list.
The problem is. Once I load the index page whatever comes back from the member_list appears straight away. Despite no ‘Cat’ being declared in the URL. Once this happens, I cannot then use the links to change it.
As you can see I have an echo for the $_GET[“Cat”]. It is changing every time the page changes.
However the rest of the page is not. I have no idea why. Nor can I work out how to fix this. If I swap the if/else if statements around. I can get the prodcat_list to appear. But then I have the same problem trying to get the member_list to appear. NFI what is going on. Im only an amateur with PHP. Getting better every day though. But I’ve a long way to go.
EDIT
I’m an idiot. Thanks everybody! ==
This
should be like this
Note the
==instead of your=! Likewise in the other if clauses later on.If you use just a single
=, you actually do an assignment. So in your case, in the if clause you try to assign the valuememberto the variable$_GET["Cat"]. As there is nothing wrong with that assignment, it is executed and the if-clause evaluates totrue.For comparisons use
==or===. The single=is just for assignments!