PHP ile Switch Kullanımı
Switch ile If kullanımındaki benzerlikler
switch.php
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
#menu { list-style: none; }
#menu ul { padding: 0; margin: 0; }
#menu li { float: left; width: 100px; height: 20px; padding: 10px; background-color: #A8032C; }
#menu li a { color: #ffffff; }
#menu li:hover { border-bottom: 2px solid cornflowerblue;}
</style>
</head>
<body>
<?php
include ('menu.php');
switch ($_GET['sayfa']) {
case 'anasayfa': include ('anasayfa.php'); break;
case 'hakkimizda': include ('hakkimizda.php'); break;
case 'galeri':include ('galeri.php'); break;
default: include ('anasayfa.php'); break;
}
/* Eğer If ile Yazmak İstersek
include ('menu.php');
if ($_GET['sayfa'] == 'anasayfa') {
include ('anasayfa.php');
} else if ($_GET['sayfa'] == 'hakkimizda') {
include ('hakkimizda.php');
} else if ($_GET['sayfa'] == 'galeri') {
include ('galeri.php');
} else {
include ('anasayfa.php');
}
*/
?>
</body>
</html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
#menu { list-style: none; }
#menu ul { padding: 0; margin: 0; }
#menu li { float: left; width: 100px; height: 20px; padding: 10px; background-color: #A8032C; }
#menu li a { color: #ffffff; }
#menu li:hover { border-bottom: 2px solid cornflowerblue;}
</style>
</head>
<body>
<?php
include ('menu.php');
switch ($_GET['sayfa']) {
case 'anasayfa': include ('anasayfa.php'); break;
case 'hakkimizda': include ('hakkimizda.php'); break;
case 'galeri':include ('galeri.php'); break;
default: include ('anasayfa.php'); break;
}
/* Eğer If ile Yazmak İstersek
include ('menu.php');
if ($_GET['sayfa'] == 'anasayfa') {
include ('anasayfa.php');
} else if ($_GET['sayfa'] == 'hakkimizda') {
include ('hakkimizda.php');
} else if ($_GET['sayfa'] == 'galeri') {
include ('galeri.php');
} else {
include ('anasayfa.php');
}
*/
?>
</body>
</html>
menu.php
<?php
/*echo '<form name = "menu" method = "get" style="clear:both">
Linkler :
<select name = "sayfa" onclick = "submit()">
<option value = "anasayfa">Ana Sayfa</option>
<option value = "hakkimizda">Hakkımızda</option>
<option value = "galeri">Galeri</option>
<option value = "iletisim">İletişim</option>
<option value = "email">Email</option>
</select>
</form>';
*/
echo '<ul id="menu">
<li><a href="switch.php?sayfa=anasayfa">Ana Sayfa</a></li>
<li><a href="switch.php?sayfa=hakkimizda">Hakkımızda</a></li>
<li><a href="switch.php?sayfa=galeri">Galeri</a></li>
</ul>
<div style="clear:both"><div>';
?>
/*echo '<form name = "menu" method = "get" style="clear:both">
Linkler :
<select name = "sayfa" onclick = "submit()">
<option value = "anasayfa">Ana Sayfa</option>
<option value = "hakkimizda">Hakkımızda</option>
<option value = "galeri">Galeri</option>
<option value = "iletisim">İletişim</option>
<option value = "email">Email</option>
</select>
</form>';
*/
echo '<ul id="menu">
<li><a href="switch.php?sayfa=anasayfa">Ana Sayfa</a></li>
<li><a href="switch.php?sayfa=hakkimizda">Hakkımızda</a></li>
<li><a href="switch.php?sayfa=galeri">Galeri</a></li>
</ul>
<div style="clear:both"><div>';
?>
anasayfa.php
<?php
echo '<div style="width: 100%; height: 50px; background-color:orange; padding: 30px;"> PHP Switch Uygulamasına Hoş Geldiniz</div>';
?>
echo '<div style="width: 100%; height: 50px; background-color:orange; padding: 30px;"> PHP Switch Uygulamasına Hoş Geldiniz</div>';
?>
galeri.php
<?php
echo '<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>';
?>
echo '<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>
<div style="width:200px; height: 200px; margin: 20px; background-color: red; float:left;"> </div>';
?>
Yorumunuzu Ekleyin