Jump to content


Photo

[SOLVED] switch statement


  • Please log in to reply
6 replies to this topic

#1 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 10 May 2006 - 10:12 PM

Is it possible for a switch statement to check against the value of a variable ?

Here is what I would like to do:


$case01 = button_caption(1);
$case02 = button_caption(2);
switch ($_REQUEST['submit'])
{
     case '$case01 ' :
         code for case01;
         break;

     case '$case02 ' :
         code for case02;
         break;
}

is this possible ?
I keep running into errors because of the single quotes.

thanks
anatak


takasi.8008@docomo.ne.jp
tourokum@0508.jp

#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 10 May 2006 - 10:16 PM

Yes its possible and you answered your own question. Use double quotes.

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 11 May 2006 - 12:43 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Use double quotes.[/quote]
Variables dont need to be within quotes.
$case01 = button_caption(1);
$case02 = button_caption(2);
switch ($_REQUEST['submit'])
{
     case $case01:
         code for case01;
         break;

     case $case02:
         code for case02;
         break;
}


#4 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 11 May 2006 - 09:08 AM

thanks

It works indeed as you said.
I could have sworn that I tried what you told me but apparantly not

Now I have another problem with IE
In Mozilla this works without problems

<script language="Javascript" type="text/javascript">
<!--
document.write('<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?page=register"?>">');
-->
</script>
<TABLE width ="100%">
<TR>
<td>SOME FIELDS TO GET DATA</td>
</tr>

<TR>
<TD colspan ="2">
<BUTTON name="submit" value="<?php echo $button=button_caption(5); ?>" type="submit"><?php echo $button=button_caption(5); ?></BUTTON>    
<BUTTON name="submit" value="<?php echo $button=button_caption(6); ?>" type="submit"><?php echo $button=button_caption(6); ?></BUTTON>    
<BUTTON name="clear" value="<?php echo $button=button_caption(2); ?>" type="reset"><?php echo $button=button_caption(2); ?></BUTTON>
</TD>
</TR>

but in IE the browser does not detect what button is pushed.
It always thinks that the last "submit" button is pushed

so in the page that receives the data it always thinks it has to run the button_caption(6) (review)script
<?php
//echo 'webpage = register<BR>';
if(!isset($_REQUEST['submit'])){
    include("home/home.inc");
//    echo "home";
}else{
    echo "submit " . $_REQUEST['submit']."</br>";//this is always review

any idea how you can use more than one submit button in a form with IE and using button ?
Or am I condemned to use input type instead ?

thank you so much
anatak
takasi.8008@docomo.ne.jp
tourokum@0508.jp

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 13 May 2006 - 06:45 AM

you gave both your buttons the same name.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 14 May 2006 - 01:30 PM

yes but if I use a $_REQUEST['submit'] the button has to be called submit I thought ?
or would this code work ?
<TR>
<TD colspan ="2">
<BUTTON name="submit" value="<?php echo $button=button_caption(5); ?>" type="submit"><?php echo $button=button_caption(5); ?></BUTTON>    
<BUTTON name="submit" value="<?php echo $button=button_caption(6); ?>" type="submit"><?php echo $button=button_caption(6); ?></BUTTON>    
<BUTTON name="clear" value="<?php echo $button=button_caption(2); ?>" type="reset"><?php echo $button=button_caption(2); ?></BUTTON>
</TD>
</TR>

and receiving the value like this

$case01 = button_caption(1);
$case02 = button_caption(2);
switch ($_REQUEST['submit'])
{
     case $case01:
         code for case01;
         break;

     case $case02:
         code for case02;
         break;
}

takasi.8008@docomo.ne.jp
tourokum@0508.jp

#7 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 12 December 2007 - 12:26 AM

problem solved
takasi.8008@docomo.ne.jp
tourokum@0508.jp




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users