0

Why doesn't this work?
I choose English and it doesn't do anything... neither does Norsk work. Anyone help please, thanks.

<?php
//nodag = Norwegian day
//endag = English Day
// dag = day
if(!isset($GET_['ok'])) { //start if
?>
<form action="" method="get">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
}// end if
elseif($GET_["lan"] = "no") { //start elseif



$endag = date("l");

switch($endag) { // start switch
	case "Monday";
	$nodag = "Mandag";
	break;
	case "Tuesday";
	$nodag = "Tirsdag";
	break;
	case "Wednesday";
	$nodag = "Onsdag";
	break;
	case "Thursday";
	$nodag = "Torsdag";
	break;
	case "Friday";
	$nodag = "Fredag";
	break;
	case "Saturday";
	$nodag = "Lordag";
	break;
	case "Sunday";
	$nodag = "Sondag";
	default:
	$nodag = "ERROR";
	} // end switch
	echo $nodag;
} // end elseif
else { // start else
$endag = date("l");
echo $endag;
}// end else
?>

Edited by Muazam: it was Code snippet, changed it to forum thread

5
Contributors
13
Replies
14
Views
7 Years
Discussion Span
Last Post by network18
Featured Replies
  • @leviathan185: You can definitely use the strings as the cases inside switch() @Mauzam : need brak after the case sunday and the syntax after the case is wrong, need to use the 'COLONS (i.e. :)' instead of ';' your improved switch() below - [CODE]switch($endag) { // start switch case "Monday": … Read More

  • 1

    There are still some typos. $GET_['formfield'] instead of $_GET['formfield']. One simple suggestion though. You don't need a switch/if-elseif-else condition to find out the day. A simple array will do it. This is what I am talking about. [code=php] <?php //nodag = Norwegian day //endag = English Day // dag = … Read More

  • 1
    diafol 3,720   7 Years Ago

    I just did the php manual's setlocale [CODE]<?php setlocale(LC_ALL, '[B]no_NO[/B]'); echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978)); ?> [/CODE] And got this: fredag 22 desember 1978 Read More

  • [QUOTE=Muazam;1049381]Ardav@ I like the setlocale solution, but Em not really looking for a date translator. I really appreciate the scripts you've made, It might be useful when I get my website up. At the moment I'm learning, the "days" could be "fruits". It doesn't matter. I just wanted to get … Read More

  • 2
    diafol 3,720   7 Years Ago

    Sorry M, this was the problem: [CODE]$day = $no(date('w'));[/CODE] should've been: [CODE]$day = $no[date('w')];[/CODE] Guess I'm not square enough! Read More

0

Why doesn't this work?
I choose English and it doesn't do anything... neither does Norsk work. Anyone help please, thanks.

<?php
//nodag = Norwegian day
//endag = English Day
// dag = day
if(!isset($GET_['ok'])) { //start if
?>
<form action="" method="get">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
}// end if
elseif($GET_["lan"] = "no") { //start elseif



$endag = date("l");

switch($endag) { // start switch
	case "Monday";
	$nodag = "Mandag";
	break;
	case "Tuesday";
	$nodag = "Tirsdag";
	break;
	case "Wednesday";
	$nodag = "Onsdag";
	break;
	case "Thursday";
	$nodag = "Torsdag";
	break;
	case "Friday";
	$nodag = "Fredag";
	break;
	case "Saturday";
	$nodag = "Lordag";
	break;
	case "Sunday";
	$nodag = "Sondag";
	default:
	$nodag = "ERROR";
	} // end switch
	echo $nodag;
} // end elseif
else { // start else
$endag = date("l");
echo $endag;
}// end else
?>

There has recently been a post similar to yours and I don't believe you can use the switch statements like that. change them to if/elseif statements

0

If you're trying to make a language switcher, I think it'll need to be a bit more rigorous, e.g. storage of language option. Is there a reason for the 'get' instead of 'post'. Is Norsk supported by locale settings? You may be able to circumvent this script entirely.

0

If you're trying to make a language switcher

Just for the days and not the entire webpage.

Is there a reason for the 'get' instead of 'post'

Nope.

My problem is, that I don't understand why my script doesn't do anything. heres the script in action: http://muazam.110mb.com/dato.php
Please tell me, what I'm doing wrong.

Edited by Muazam: n/a

1

@leviathan185: You can definitely use the strings as the cases inside switch()
@Mauzam : need brak after the case sunday and the syntax after the case is wrong, need to use the 'COLONS (i.e. :)' instead of ';'
your improved switch() below -

switch($endag) { // start switch
	case "Monday":
	$nodag = "Mandag";
	break;
	case "Tuesday":
	$nodag = "Tirsdag";
	break;
	case "Wednesday":
	$nodag = "Onsdag";
	break;
	case "Thursday":
	$nodag = "Torsdag";
	break;
	case "Friday":
	$nodag = "Fredag";
	break;
	case "Saturday":
	$nodag = "Lordag";
	break;
	case "Sunday":
	$nodag = "Sondag";
	break;
	default:
	$nodag = "ERROR";
	} // end switch

I did not check with the rest of your code yet,i assume the rest is fine.

1

There are still some typos. $GET_ instead of $_GET. One simple suggestion though. You don't need a switch/if-elseif-else condition to find out the day. A simple array will do it. This is what I am talking about.

<?php
//nodag = Norwegian day
//endag = English Day
// dag = day
if(!isset($_GET['ok'])) { //start if
?>
<form action="" method="get">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
}// end if
elseif($_GET["lan"] = "no") { //start elseif
$norwegian_days = array("Monday"=>"Mandag","Tuesday"=>"Tirsdag","Wednesday"=>"Onsdag","Thursday"=>"Torsdag","Friday"=>"Fredag","Saturday"=>"Lordag","Sunday"=>"Sondag");
$endag = date("l");
$nodag = $norwegian_days[$endag];
echo $nodag;
} // end elseif
else { // start else
$endag = date("l");
echo $endag;
}// end else
?>

Cheers!

1

I just did the php manual's setlocale

<?php
setlocale(LC_ALL, '[B]no_NO[/B]');
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
?>

And got this:
fredag 22 desember 1978

Edited by diafol: n/a

0

Thanks Nav33en, Ardav and net.
It still has some problems.

<?php
//nodag = Norwegian day
//endag = English Day
// dag = day
if(!isset($_GET['ok'])) { //start if
?>
<form action="" method="get">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
}// end if
elseif($_GET["lan"] = "no") { //start elseif
	$norwegian_days = array("Monday"=>"Mandag","Tuesday"=>"Tirsdag","Wednesday"=>"Onsdag","Thursday"=>"Torsdag","Friday"=>"Fredag","Saturday"=>"Lordag","Sunday"=>"Sondag");
	$endag = date("l");
	$nodag = $norwegian_days[$endag];
echo $nodag;
} // end elseif
elseif($_GET["lan"] = "eng") { // start else
	$endag = date("l");
echo $endag;
}// end else
?>

In action : http://muazam.110mb.com/datoe.php
When I choose English, it still shows Norwegian days.

1

OK, if you didn't like the setlocale solution, how about this?

//the following code sets English as the default language unless Norsk is selected.
<?php
  if(isset($_POST['lan'] && $_POST['lan'] == 'no')){
     $no = array("Sondag","Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lordag");
     $day = $no(date('w'));
  }else{
     $day = date('l');
  }
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
  echo $day;
?>

No need for a switch statement unless you have loads of languages to test. Notice I also changed the method from get to post. Just simplifies things - users less inclined to mess with the querystring.


However, I still think the setlocale is easier:

<?php
//Norsk
setlocale(LC_ALL, 'no_NO');
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978)) . "<br />";
//Cymraeg-Welsh
setlocale(LC_ALL, 'cy_GB');
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978)) . "<br />";
//English
setlocale(LC_ALL, 'en_GB');
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
?>

Gave:

fredag 22 desember 1978
Gwener 22 Rhagfyr 1978
Friday 22 December 1978

Edited by diafol: n/a

0

Ardav@ I like the setlocale solution, but Em not really looking for a date translator. I really appreciate the scripts you've made, It might be useful when I get my website up.

At the moment I'm learning, the "days" could be "fruits". It doesn't matter. I just wanted to get the function working.

Ardav those scripts above doesn't work ><< Might just be my host. I try another host tomorrow.
Thanks for the help, I really appreciate it =)

Edited by Muazam: n/a

2

Ardav@ I like the setlocale solution, but Em not really looking for a date translator. I really appreciate the scripts you've made, It might be useful when I get my website up.

At the moment I'm learning, the "days" could be "fruits". It doesn't matter. I just wanted to get the function working.

Ardav those scripts above doesn't work ><< Might just be my host. I try another host tomorrow.
Thanks for the help, I really appreciate it =)

The script in your #post 8 is modified as below, I am sure it will work for you -

<?php
//nodag = Norwegian day
//endag = English Day
// dag = day\

if(!isset($_GET['ok'])) { //start if
?>
<form action="" method="get">
<select name="lan">
	<option value="eng">English</option>
	<option value="no">Norsk</option>
	</select>
<input type="submit" name="ok" value="Ok">
</form>
<?php
}// end if
elseif(isset($_GET["lan"]) && $_GET["lan"] == "no") { //start elseif
	$norwegian_days = array("Monday"=>"Mandag","Tuesday"=>"Tirsdag","Wednesday"=>"Onsdag","Thursday"=>"Torsdag","Friday"=>"Fredag","Saturday"=>"Lordag","Sunday"=>"Sondag");
	$endag = date("l");
	$nodag = $norwegian_days[$endag];
echo $nodag;
} // end elseif
elseif(isset($_GET["lan"]) && $_GET["lan"] == "eng") { // start else
	$endag = date("l");
echo $endag;
}// end else
?>

Hope you noticed the small change

Votes + Comments
Very helpful
Darn! I totally missed the == in my post. Good work!
2

Sorry M, this was the problem:

$day = $no(date('w'));

should've been:

$day = $no[date('w')];

Guess I'm not square enough!

0

Thanks for the help Network and Ardav.
Network it worked like I wanted it too, thank you.

Edited by Muazam: n/a

0

Thanks for the help Network and Ardav.
Network it worked like I wanted it too, thank you.

my pleasure!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.