Page 1 of 1

Div and php playing nice together

Posted: Thu Jan 28, 2010 3:54 pm
by jefffan24
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

Re: Div and php playing nice together

Posted: Thu Jan 28, 2010 4:42 pm
by JakeJ
cakephp might be able to handle that very well.

Re: Div and php playing nice together

Posted: Thu Jan 28, 2010 4:48 pm
by social_experiment
It seems you are talking about query strings.

Code: Select all

<?php
 echo "<a href=\"linkName.php?div=A\">Div A</a>";
?>
The value of 'div' will be available in the $_GET['div'] variable. Accessing it would be something like :

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

Re: Div and php playing nice together

Posted: Thu Jan 28, 2010 8:26 pm
by jefffan24
so would the case's be the div's? If so would I put the div tags inside the Cases?

Like

Code: Select all

Case ('A'):
echo '<div name="A">';
break;
 
 

Re: Div and php playing nice together

Posted: Fri Jan 29, 2010 12:14 am
by social_experiment
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;
?>
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
I think the answer about query strings is what you were looking for though. :)

Re: Div and php playing nice together

Posted: Sat Jan 30, 2010 7:14 am
by jefffan24
Got it working thanks to all that helped :D