Jump to content
php.lv forumi

Switch


Llama

Recommended Posts

Sveiki, sen te neesmu bijis, vajadzīga jūsu palīdzība, lieta tāda esmu izveidojis switchu, kur pārleks no vienas lapas uz otru, un kad es ieeju lapā, tad jaunumos nelasa news.php failu, bet kad uzspiež uz sākums tad lasa. piemēram localhost/index.php - tad news ir tukš, jo nelasa informāciju no news if nestrādā pie default, bet kad ir localhost/index.php?page=sakums tad visu rāda.

<?php 
	if (isset($_GET['page']))
{
	switch($_GET['page'])
		{
        case 'Sakums':
        include("news.php");
        break;
		
		case 'Par mums':
        include("about.php");
        break;
		
		case 'Vakances':
        include("vakances.php");
        break;	
		
		case 'Kontakti':
        include("contact.php");
        break;
		
		case 'Akcijas':
        include("akcijas.php");
        break;
		
		case 'Galerija':
        include("galerija.php");
        break;
				
		default:
		include ("news.php");
		
		
    } 
}

?>	

Menu

<li><a href='index.php?page=Sakums'>Sākums</a></li>
Link to comment
Share on other sites

Nelieto to sūda switchu, izmanto vienkārši masīvu:

 

Daudz foršāk:

$pages = array(
   'Par mums' => 'about',
   'Galerija' => 'gallery',
   'Akcijas' => 'akcijas',
   'Zinas' => 'news',
);

$page = isset($_GET['page']) ? $_GET['page'] : 'Zinas';

if(!isset($pages[$page])){
   $page = 'Zinas';
}

include $pages[$page] . '.php';
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...