Llama Posted January 30, 2015 Report Share Posted January 30, 2015 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> Quote Link to comment Share on other sites More sharing options...
Blitz Posted January 30, 2015 Report Share Posted January 30, 2015 (edited) Tev jau tas switch strādā tikai pie nosacījuma if (isset($_GET['page'])), ja atver localhost/index.php tad tas būs false Edited January 30, 2015 by Blitz Quote Link to comment Share on other sites More sharing options...
briedis Posted January 30, 2015 Report Share Posted January 30, 2015 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'; Quote Link to comment Share on other sites More sharing options...
Llama Posted January 30, 2015 Author Report Share Posted January 30, 2015 Massīvi man ir svešāka lieta, neprotu ar tiem īsti darboties, tāpēc, ja prasīst nespēšu atbildēt kas notiek, tāpēc izmantoju switch, tad kā jābūt pareizi? Blitz? Quote Link to comment Share on other sites More sharing options...
Kavacky Posted January 30, 2015 Report Share Posted January 30, 2015 (edited) $page = isset($_GET['page']) ? $_GET['page'] : 'Sakums'; switch ($page) { case 'Par mums': include('about.php'); break; ... case 'Sakums': default: include('news.php'); break; } Edited January 30, 2015 by Kavacky Quote Link to comment Share on other sites More sharing options...
briedis Posted January 30, 2015 Report Share Posted January 30, 2015 Masīvs taču ir elementāra struktūra. Bez masīviem tu neko normāli nevarēsi izdarīt. Izstudē šo un viss būs skaidrs. http://www.tizag.com/phpT/arrays.php Vispār, pastudē tās tizag.com lapas resursus, tur diezgan vienkārši un saprotami piemēri. Quote Link to comment Share on other sites More sharing options...
Llama Posted January 30, 2015 Author Report Share Posted January 30, 2015 Paldies. Noteikti. Paldies par atsaucību. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.