Page 1 of 1

switch

Posted: Tue Jul 08, 2003 7:22 am
by tranquillo
hi...
I've made a switch that looks pretty much like this:

--------------------------

<?php
switch($switch) {
case 1:
?>
<div id="ny" class="login">
content
</div>
<?php
break;

case 2:
?>
<div id="prod" class="login">
content
</div>
<?php
break;

default:
echo "whatever";
break;
}
?>

--------------------------

and a menu that looks like this:

--------------------------

<a href="#" class="login" onClick="<?php $switch=1; ?>">
Uppdatera nyheter</a><br>

<a href="#" class="login" onClick="<?php $switch=2; ?>">
Uppdatera produkter</a>

--------------------------

what am I doing wrong?
I allso tried making the menu as a form with a hidden text field adding the number to $switch.. but it didn't work either...

Posted: Tue Jul 08, 2003 8:53 am
by Joan Garnet
I don't understand this piece of code:

Code: Select all

<a href="#" class="login" onClick="<?php $switch=1; ?>">
Uppdatera nyheter</a><br>

<a href="#" class="login" onClick="<?php $switch=2; ?>">
Uppdatera produkter</a>


It looks like if you want to change the value of $switch using javascript and that is not possible.
You will have to create a javascript function that will send POST or GET vars to the server, where $switch will be changed by using a php script.

Posted: Tue Jul 08, 2003 9:12 am
by tranquillo
I tried something like that before...

I did a form with a hidden text field that gave $switch the number for the case.. but it didn't work... is there another way of doing this?

Posted: Tue Jul 08, 2003 9:48 am
by Joan Garnet
I would do the following:

Code: Select all

<a href="#" class="login" onClick="window.href='my_file.php?sw=1'">Uppdatera nyheter</a><br>
<a href="#" class="login" onClick="window.href='my_file.php?sw=2'">Uppdatera produkter</a>

and the php script in my_file.php:

Code: Select all

<?php
switch( $_GET["sw"] ) {
   case 1:
      ?>
      <div id="ny" class="login">
      content
      </div>
      <?php
      break;

   case 2:
      ?>
      <div id="prod" class="login">
      content
      </div>   
      <?php
      break;
   default:
      echo "whatever";
      break;
}
?>