Ok I know the subject isn't the most helpful but just here me out:
I have a site where multiple divs are being shown or hidden based on where the user clicks. Now lets say he clicks on Div A well then Div B and Div C will hidden with javascript. If he then clicks on the link to show Div B then Div A and Div C are hidden again with javascript. Same thing with Div C it hides Div A and Div B.
Now if the page refreshes it goes back to the default (all divs hidden) rather then remember which one was open last. How I was thinking of making this work is lets say example.com/index.php is my website.
When they click on a div the url becomes example.com/index.php?div=A or example.com/index.php?div=B
My problem with doing it this way is I don't know how to make php for change the url based on which link a user clicks, and how to make it so that which ever div is in url is the one that is open. Any help would be greatly appreciated and if you need any more clarification please let me know. I know I can be confusing sometimes :p
Div and php playing nice together
Moderator: General Moderators
Re: Div and php playing nice together
cakephp might be able to handle that very well.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Div and php playing nice together
It seems you are talking about query strings.
The value of 'div' will be available in the $_GET['div'] variable. Accessing it would be something like :
Code: Select all
<?php
echo "<a href=\"linkName.php?div=A\">Div A</a>";
?>Code: Select all
<?php
if (isset($_GET['div'])) {
switch($_GET['div']) {
case('A'):
//do something
break;
case('B'):
//do something
break;
case('C'):
//do something
break;
default:
//do someting default like
break;
}
}
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Div and php playing nice together
so would the case's be the div's? If so would I put the div tags inside the Cases?
Like
Like
Code: Select all
Case ('A'):
echo '<div name="A">';
break;
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Div and php playing nice together
The switch statement checks the value of the div, if you want something to happen for each div (for example if a user clicks on div A redirect them to a page about div A), you would place that code inside the case statement.

Code: Select all
<?php
case('A'):
//display page or something relevant
break;
?>I think the answer about query strings is what you were looking for though.My problem with doing it this way is I don't know how to make php for change the url based on which link a user clicks, and how to make it so that which ever div is in url is the one that is open. Any help would be greatly appreciated and if you need any more clarification please let me know. I know I can be confusing sometimes :p
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Div and php playing nice together
Got it working thanks to all that helped 