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

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

Member Avatar for diafol

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.

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.

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

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!

Member Avatar for diafol

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

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.

Member Avatar for diafol

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

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 =)

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

commented: Darn! I totally missed the == in my post. Good work! +5
commented: Very helpful +1
Member Avatar for diafol

Sorry M, this was the problem:

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

should've been:

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

Guess I'm not square enough!

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

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

my pleasure!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.