Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> Jak zrobić by adres strony był..., ...np. index.php?id=1
mat_1200
post
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Witam!!
Mam problem. Chce żeby adres strony był np taki: index.php?id=1
Słyszałem, że trzeba użyć do tego $_GET - a , ale nie wiem jak. Sam skonstruowałem taki oto kod:
  1. <?
  2.  
  3. if ($_GET['go'] !== '') {
  4.  
  5. switch
  6. case 1:
  7. include'index.php';
  8. break;
  9.  
  10. case 2:
  11. include'a.txt';
  12. break;
  13.  
  14. case 3:
  15. include'index2.php';
  16. break;
  17.  
  18. default:
  19.  include'index.php';}
  20.  
  21. ?>
  22. <a href="get.php?go=1">1</a>
  23. <a href="get.php?go=2">2</a>
  24. <a href="get.php?go=3">3</a>


Lecz wyświetla mi Parse Error. Korzystam w Krasnal-SERV.
Pomóżcie!!!!!!!
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




przyjrzyj sie skladni switch a sam bedziesz wiedzial gdzie masz blad:
http://pl.php.net/manual/pl/control-structures.switch.php
Go to the top of the page
+Quote Post
imashjan
post
Post #3





Grupa: Zarejestrowani
Postów: 73
Pomógł: 0
Dołączył: 30.11.2005

Ostrzeżenie: (0%)
-----


Naprzykład można zrobić tak:
  1.  <?
  2.  $id=$_GET["id"];
  3. if(!isset($id)) {
  4. include("dane/tresc.php");
  5. }
  6. else {
  7. if(is_file("dane/$id.php")) {
  8. include("dane/$id.php");
  9. }
  10. else
  11. echo "<div class=tresc>Blad taka strona nie istnieje</div>";
  12. }
  13.  ?>
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




@imashjan brawoooo. Najpierw pobierac cos a potem dopiero patrzysz czy to cos istenieje. jeszzcze raz brawo.
Go to the top of the page
+Quote Post
mat_1200
post
Post #5





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Mam pytanie do imashjan'a czy ten kod bedzie dziala jesli bede chcial wincludowac w strone inna strone?

======================
Zmieniłem kod. Teraz wyglada tak:

  1. <?
  2. $go = $_GET['go'] ;
  3. if ($_GET['go'] !== '') {
  4.  
  5. switch ($go)
  6. case 1:
  7. include'index.php';
  8. break;
  9.  
  10. case 2:
  11. include'a.txt';
  12. break;
  13.  
  14. case 3:
  15. include'index.php';
  16. break;
  17.  
  18. default:
  19.  include'index.php';}
  20.  
  21. ?>
  22. <a href="get.php?go=1">1</a>
  23. <a href="get.php?go=2">2</a>
  24. <a href="get.php?go=3">3</a>


I wyświetla mi "Parse error: parse error, expecting `':'' or `'{'' in c:\usr\apache\httpd\html\www\site kod\php\get.php on line 6".

Ten post edytował mat_1200 17.12.2005, 19:58:16
Go to the top of the page
+Quote Post
imashjan
post
Post #6





Grupa: Zarejestrowani
Postów: 73
Pomógł: 0
Dołączył: 30.11.2005

Ostrzeżenie: (0%)
-----


1) ten kod pochodzi od kess-a on na swojej stronie mial jako przyklad, to wystarczy zamienic chyba nie, niech najpierw sprawdza, a potem dobiero dziala,
2) nie wiem ja tylko includuje pliki, a nie cale strony,
Go to the top of the page
+Quote Post
nospor
post
Post #7





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




@mat_1200 * zajrzales do tego manuala? Bo chyba nie. Jaka jest skladania switch? NIe zapomaniales o {? potem tylko nie zapomnij zamknac dla switcha i dla ifa
Go to the top of the page
+Quote Post
mat_1200
post
Post #8





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Dobra jakos to choadzi ale wyswietla mi sie zawartość a.txt

Ten post edytował mat_1200 17.12.2005, 20:02:52
Go to the top of the page
+Quote Post
nospor
post
Post #9





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




bo pewnie masz w url go=2

i nie kasuj swoich postow bo potem niedomowienia wychodza
Go to the top of the page
+Quote Post
mat_1200
post
Post #10





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Dzieki wam! (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Mam problem. Gdy wpisze index.php?go=1 to wyswieli mi sie strona startowa a gdy wpisze index.php?go=4 to strona sie nie zmieni czemu??

  1. <?
  2. $go = $_GET['go'] ;
  3. if ($_GET['go'] !== '') {
  4.  
  5. switch ($go) {
  6. case 1:
  7. include'tables/table_news.php';
  8. break;
  9.  
  10. case 2:
  11. include'fragments/rekrutacja.php';
  12. break;
  13.  
  14. case 3:
  15. include'fragments/sparing.php';
  16. break;
  17.  
  18. case 4:
  19. include'fragments/wojny_klanowe.php';
  20. break;
  21.  
  22. case 5:
  23. include'fragments/historia_klanu.php';
  24. break;
  25.  
  26. case 6:
  27. include'fragments/trening.php';
  28. break;
  29.  
  30. case 7:
  31. include'fragments/news.php';
  32. break;
  33.  
  34. case 8:
  35. include'fragments/server.php';
  36. break;
  37.  
  38. case 9:
  39. include'fragments/ts.php';
  40. break;
  41.  
  42. case 10:
  43. include'fragments/czarna_lista.php';
  44. break;
  45.  
  46. case 11:
  47. include'fragments/weterani.php';
  48. break;
  49.  
  50. case 12:
  51. include'fragments/regulamin.php';
  52. break;
  53.  
  54. case 13:
  55. include'fragments/download.php';
  56. break;
  57.  
  58. case 14:
  59. include'fragments/galeria.php';
  60. break;
  61.  
  62. case 15:
  63. include'fragments/polskie_klany.php';
  64. break;
  65.  
  66. case 16:
  67. include'fragments/bany.php';
  68. break;
  69.  
  70. case 17:
  71. include'fragments/linki.php';
  72. break;
  73.  
  74. case 18:
  75. include'fragments/forum.php';
  76. break;
  77.  
  78. case 19:
  79. include'fragments/kalendarz.php';
  80. break;
  81.  
  82. case 20:
  83. include'fragments/ksiega_gosci.php';
  84. break;
  85.  
  86. case 21:
  87. include'fragments/kontakt.php';
  88. break;
  89.  
  90. default:
  91.  include'tables/table_news.php';
  92. }
  93.  }
  94.  
  95. ?>


Ten post edytował mat_1200 18.12.2005, 20:18:08
Go to the top of the page
+Quote Post
mike
post
Post #11





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Tablic mógłbyś sie nauczyć. W życiu Ci łatwiej będzie:
  1. <?php
  2.  
  3. $arrIncludes = array( 
  4. 0 => 'tables/table_news.php',
  5. 1 => 'tables/table_news.php',
  6. 2 => 'fragments/rekrutacja.php',
  7. 3 => 'fragments/sparing.php',
  8. 4 => 'fragments/wojny_klanowe.php'
  9. );
  10.  
  11. $_GET[ 'go' ] = ( empty( $_GET[ 'go' ] ) ) ? 0 : $_GET[ 'go' ];
  12.  
  13. include( $arrIncludes[ $_GET[ 'go' ] ] );
  14.  
  15. ?>
Go to the top of the page
+Quote Post
Balon
post
Post #12





Grupa: Zarejestrowani
Postów: 422
Pomógł: 0
Dołączył: 14.12.2005
Skąd: Wałbrzych

Ostrzeżenie: (0%)
-----


Chyba najlatwiejszy sposob

  1. <?
  2. if($id=="1") { include "inc/jakasstrona.php"; }
  3. elseif($id=="2") { include "inc/jakasstrona2.php"; }
  4. elseif($id=="3") { include "inc/jakasstrona3.php"; }
  5. else { include "inc/jakasstrona.php"; }
  6. ?>
Go to the top of the page
+Quote Post
mike
post
Post #13





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Cytat(Balon @ 2005-12-18 21:55:56)
Chyba najlatwiejszy sposob (...)

... i tak samo beznadziejny jak pomysł mat_1200 (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
mat_1200
post
Post #14





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Jest ten sam efekt zrówno przy moim kodzie jak i tym z tablicami

P.S. Umiem tablice(Rzadko je stosuje:))
Go to the top of the page
+Quote Post
ens0re
post
Post #15





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 23.08.2005
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


A obczaj taki skrypt:
  1. <?
  2. $id = $_GET['id'];
  3. if ( !isset ( $id ) ) include ( "id/news.txt" );
  4. else if ( is_file ( 'id/'.$id.'.txt' ) ) include ( 'id/'.$id.'.txt' );
  5. else echo ( 'Przepraszamy...Strona Nie Istnieje!!!' );
  6. ?>

Pliki *.txt w katalogu ID, linki: index.php?id=link...
Go to the top of the page
+Quote Post
mat_1200
post
Post #16





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


ostatni skrypt mi nie chodzi...

Mi chodzi o to że jak klikne na inny link to strona wgrywa sie ta sama!!

Ten post edytował mat_1200 19.12.2005, 19:51:54
Go to the top of the page
+Quote Post
Ociu
post
Post #17





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Cytat
P.S. Umiem tablice(Rzadko je stosuje:))

Widze, że kolega zatrzymał się na skrypcie
  1. <?php print 'Hello world!'; ?>

A nie, sory:
  1. <?php
  2. echo("Hello World!");
  3. ?>
Go to the top of the page
+Quote Post
-HubbaBubba-
post
Post #18





Goście







pisze sie "!=" a nie "!=="

  1. <?
  2.  
  3. if ($_GET['go'] != '') {
  4.  
  5.  
  6. ?>
Go to the top of the page
+Quote Post
mike
post
Post #19





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Cytat(HubbaBubba @ 2005-12-20 12:24:48)
pisze sie "!=" a nie "!=="
LOL (IMG:http://forum.php.pl/style_emoticons/default/laugh.gif)

Pisze się i tak, i tak. To są dwie różne rzeczy a nie literówka jak Ci się wydaje (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
dtb
post
Post #20





Grupa: Zarejestrowani
Postów: 476
Pomógł: 1
Dołączył: 5.11.2005
Skąd: Bieruń city

Ostrzeżenie: (0%)
-----


ja proponuje to zrobic w ten sposob:

table.txt:
Kod
tables/table_news.php
fragments/rekrutacja.php
fragments/sparing.php
(..)


index.php:
  1. <?php
  2. $uchwyt = fopen ("table.txt", "r");
  3. for ($i=1;!feof ($uchwyt) AND $i>0; $i++) {
  4.  $buffer = fgets($uchwyt, 64);
  5.  if ($_GET['go'] == $i)
  6. {
  7. include $buffer;
  8. $i=-1;
  9. }
  10. }
  11. fclose ($uchwyt);
  12. ?>


Ten post edytował dtb 20.12.2005, 17:46:22
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.12.2025 - 05:48