Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Pętla i wartość zmiennej
Forum PHP.pl > Forum > PHP
felixk
Witam, mam taki o to problem. Piszę edytor plików dla strony www z wykorzystaniem tinyMCE. Aktualny plik do edycji wczytuję przez <select onchange=""><option></option</select>. Te znaczniki mam w pętli, ale nie bardzo wiem jak przekazać każdej podstronie odpowiednią wartość tzn. nazwę pliku, który ma być edytowany. Za wszelkie pomysły będę wdzięczny

W tej chwili wygląda to tak:

  1. echo '<select onchange="self.location.href = this.value">
  2. <option VALUE="-- Wybierz podstronę --" selected>Wybierz podstronę</option>';
  3.  
  4. for( $x = 0; $ile = count($files), $x < $ile; $x++ )
  5. {
  6. echo "<option value=\"edytor.php?edytor=$files[i]\">";
  7. echo $files[$x];
  8. echo '</option>';
  9. }
  10. echo '</select>';
wookieb
A spójrz w źródło strony i w wartości atrybutu "value" jakie wygenerowałeś
felixk
Cytat(wookieb @ 14.06.2012, 07:47:18 ) *
A spójrz w źródło strony i w wartości atrybutu "value" jakie wygenerowałeś


wartość value jest pusta niestety i stąd jest właśnie moje pytanie
IProSoft
Sprawdź:
  1. $ile = count($files);
  2.  
  3. for( $x = 0; $x < $ile; $x++ )
  4. {
  5. echo '<option value="edytor.php?edytor=' . $files[$x] . '">' . $files[$x] . '</option>';
  6. }
felixk
mam jeszcze taki problem, bo o ile faktycznie wartości zmienna już ma. Dziękuję za wzór, to teraz nie wczytuje mi zawartości pliku z instrukcji switch. Co robię źle i jak to poukładać?

Komunikat błędu:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_CASE or T_DEFAULT or '}' in ......

  1. $tab1 = array('<p>', '</p>');
  2. $tab2 = array("", "");
  3.  
  4. if(!isset($_GET['edytor']))
  5.  
  6. {
  7.  
  8. $_GET['edytor'] = 'edytor.php';
  9.  
  10. }
  11.  
  12.  
  13. switch($_GET['edytor'])
  14.  
  15. {
  16.  
  17. $ile = count($files);
  18.  
  19. echo '<select onchange="self.location.href = this.value">
  20. <option VALUE="-- Wybierz podstronę --" selected>Wybierz podstronę</option>';
  21.  
  22. for( $x = 0; $x < $ile; $x++ )
  23. {
  24. echo '<option value="edytor.php?edytor=' . $files[$x] . '">' . $files[$x] . '</option>';
  25. }
  26. echo '</select>';
  27. echo '<input class="submit" type="submit" value="Zapisz" />';
  28.  
  29.  
  30. echo'</form>';
  31.  
  32. case 'o_nas':
  33.  
  34. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  35. $a = file_get_contents('../'.$files[$x].'');
  36. echo $a;
  37. echo '</textarea><br />';
  38.  
  39. echo '<input class="submit" type="submit" value="Zapisz" />';
  40. $editor_data = stripslashes($_POST['content']);
  41. $editor_data = str_replace($tab1, $tab2, $editor_data);
  42. $editor_data = html_entity_decode($editor_data);
  43. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  44.  
  45. echo'</form>';
  46. break;
  47.  
  48.  
  49. case 'dzialalnosc_tpd':
  50.  
  51. echo'<div style="text-align: center"><form method="post"><textarea name="content" cols="90" rows="10">';
  52. $a = file_get_contents('../'.$files[$x].'');
  53. echo $a;
  54. echo '</textarea><br />';
  55.  
  56. echo ' <input class="submit" type="submit" value="Zapisz" />';
  57. $editor_data = stripslashes($_POST['content']);
  58. $editor_data = str_replace($tab1, $tab2, $editor_data);
  59. $editor_data = html_entity_decode($editor_data);
  60. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  61.  
  62. echo'</form>';
  63. break;
  64.  
  65.  
  66. case 'jeden_procent':
  67.  
  68. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  69. $a = file_get_contents('../'.$files[$x].'');
  70. echo $a;
  71. echo '</textarea><br />';
  72.  
  73. echo ' <input class="submit" type="submit" value="Zapisz" />';
  74. $editor_data = stripslashes($_POST['content']);
  75. $editor_data = str_replace($tab1, $tab2, $editor_data);
  76. $editor_data = html_entity_decode($editor_data);
  77. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  78. echo'</form>';
  79. break;
  80.  
  81.  
  82. case 'sow_tpd':
  83.  
  84. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  85. $a = file_get_contents('../'.$files[$x].'');
  86. echo $a;
  87. echo '</textarea><br />';
  88.  
  89. echo ' <input class="submit" type="submit" value="Zapisz" />';
  90. $editor_data = stripslashes($_POST['content']);
  91. $editor_data = str_replace($tab1, $tab2, $editor_data);
  92. $editor_data = html_entity_decode($editor_data);
  93. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  94.  
  95. echo'</form>';
  96.  
  97. break;
  98.  
  99.  
  100. case 'sow_tpd_adresy':
  101.  
  102. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  103. $a = file_get_contents('../'.$files[$x].'');
  104. echo $a;
  105. echo '</textarea><br />';
  106.  
  107. echo ' <input class="submit" type="submit" value="Zapisz" />';
  108. $editor_data = stripslashes($_POST['content']);
  109. $editor_data = str_replace($tab1, $tab2, $editor_data);
  110. $editor_data = html_entity_decode($editor_data);
  111. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  112.  
  113. echo'</form>';
  114. break;
  115.  
  116.  
  117. case 'nasi_przyjaciele':
  118.  
  119. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  120. $a = file_get_contents('../'.$files[$x].'');
  121. echo $a;
  122. echo '</textarea><br />';
  123.  
  124. echo ' <input class="submit" type="submit" value="Zapisz" />';
  125. $editor_data = stripslashes($_POST['content']);
  126. $editor_data = str_replace($tab1, $tab2, $editor_data);
  127. $editor_data = html_entity_decode($editor_data);
  128. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  129.  
  130. echo'</form>';
  131. break;
  132.  
  133.  
  134. case 'zostan_naszym_przyjacielem':
  135.  
  136. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  137. $a = file_get_contents('../'.$files[$x].'');
  138. echo $a;
  139. echo '</textarea><br />';
  140.  
  141. echo ' <input class="submit" type="submit" value="Zapisz" />';
  142. $editor_data = stripslashes($_POST['content']);
  143. $editor_data = str_replace($tab1, $tab2, $editor_data);
  144. $editor_data = html_entity_decode($editor_data);
  145. $b = file_put_contents('../'.$files[$x].'',$editor_data);
  146.  
  147. echo'</form>';
  148. break;
  149.  
  150.  
  151. case 'rzecznik_praw_dziecka':
  152.  
  153. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  154. $a = file_get_contents('../'.$files[$x].'');
  155. echo $a;
  156. echo '</textarea><br />';
  157.  
  158. echo '<input class="submit" type="submit" value="Zapisz" />';
  159. $editor_data = stripslashes($_POST['content']);
  160. $editor_data = str_replace($tab1, $tab2, $editor_data);
  161. $editor_data = html_entity_decode($editor_data);
  162. $b = file_put_contents('../'.$files[$x].'', $editor_data);
  163.  
  164. echo'</form>';
  165. break;
  166.  
  167.  
  168. case 'obchody_roku_korczakowskiego':
  169.  
  170. echo'<form method="post"><textarea name="content" cols="90" rows="10">';
  171. $a = file_get_contents('../'.$files[$x].'');
  172. echo $a;
  173. echo '</textarea><br />';
  174.  
  175. echo ' <input class="submit" type="submit" value="Zapisz" />';
  176. $editor_data = stripslashes($_POST['content']);
  177. $editor_data = str_replace($tab1, $tab2, $editor_data);
  178. $editor_data = html_entity_decode($editor_data);
  179. $b = file_put_contents('../'.$files[$x].'', $editor_data);
  180.  
  181. echo'</form>';
  182.  
  183. break;
  184.  
  185. default:
  186. echo ' domyślny tekst';
irmidjusz
Masakra. Kolego, w jakim programie piszesz kod? Myślałem, że nie ma już takich edytorów, które nie pokazują na bieżąco miejsc występowania błędów składniowych....
IProSoft
@UP są cały czas ale to nie znaczy, że każdy zaraz musi przeżucać się na jakieś IDE...

Masz błąd w składnie, tj :
  1. switch($_GET['edytor'])
  2. {
  3. //tutaj nie możesz nic dodać a wrzucasz kod, dj go przed switch;
  4. case "":
  5. //warunek
  6. break;
  7. default:
  8. //kolejny warunek
  9. break;
  10. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.