switch

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

tranquillo
New php-forum User
New php-forum User
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm
Contact:

switch

Postby tranquillo » Tue Jul 08, 2003 7:22 am

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...

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Jul 08, 2003 8:53 am

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.

tranquillo
New php-forum User
New php-forum User
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm
Contact:

Postby tranquillo » Tue Jul 08, 2003 9:12 am

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?

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Jul 08, 2003 9:48 am

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


Return to “PHP coding => General”

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

cron