Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP/MySQL] Select powinno zaznaczyć, a nie zaznacza
Forum PHP.pl > Forum > Przedszkole
Koniczynka
Witajcie,

Mam problem z funkcją, która powinna zaznaczać select przez explode'owane dane.

  1. <?php
  2. function rezerwowi()
  3. {
  4. $this->wyciaganie();
  5. $this->rezerwowibaza = $this->row['zmiany_mecze'];
  6. $this->rezer = explode("ćó" , $this->rezerwowibaza);
  7.  
  8. $this->rezer1 = $this->rezer[0];
  9. $this->rezer2 = $this->rezer[3];
  10. $this->rezer3 = $this->rezer[4];  
  11. $this->rezer4 = $this->rezer[5];
  12. $this->rezer5 = $this->rezer[2];
  13. $this->rezer6 = $this->rezer[1];
  14.  
  15. $this->rezer7 = $this->rezer[6];
  16. $this->rezer8 = $this->rezer[9];
  17. $this->rezer9 = $this->rezer[10];
  18. $this->rezer10 = $this->rezer[11];
  19. $this->rezer11 = $this->rezer[8];
  20. $this->rezer12 = $this->rezer[7];
  21. $this->rezer13 = $this->rezer[12];
  22. $this->rezer14 = $this->rezer[15];
  23. $this->rezer15 = $this->rezer[16];
  24. $this->rezer16 = $this->rezer[17];
  25. $this->rezer17 = $this->rezer[14];
  26. $this->rezer18 = $this->rezer[13];
  27. $this->rezer19 = $this->rezer[18];
  28. $this->rezer20 = $this->rezer[21];
  29. $this->rezer21 = $this->rezer[22];
  30. $this->rezer22 = $this->rezer[23];
  31. $this->rezer23 = $this->rezer[20];
  32. $this->rezer24 = $this->rezer[19];
  33. echo $this->rezer1;
  34. echo "<select name=nam>";
  35. $this->pytaniea10="SELECT * FROM zawodnicy ORDER BY nazwisko_zawodnicy ASC "; 
  36. $this->result3a10 = mysql_query ($this->pytaniea10) 
  37.  or die ("błąd zapytania "); 
  38. while ($this->row3a10 = mysql_fetch_array ($this->result3a10)){ 
  39. if ($this->row3a10['id_zawodnicy'] == $this->rezer1) $this->zaznacz="selected"; else $this->zaznacz=""; 
  40.  
  41. echo "<option value='".$this->row3a10['id_zawodnicy']."' ".$this->zaznacz.">".$this->row3a10['nazwisko_zawodnicy']." ".$this->row3a10['imie_zawodnicy']."</option>"; 
  42. } 
  43. echo "</select>";
  44. }
  45. ?>


Problem tkwi w $this->rezer1 . Otóż kiedy jest wywoływana jego wartość, pokazuje się ona zgodnie z prawdą. Kiedy pobieram dane z WHERE id_zawodnicy = $this->rezer1, także działa. Jednak w wypadku, w którym ma zaznaczać dodane wcześniej pole, $this->rezer1 przybiera pustą wartość. Dlaczego tak się dzieje, bo moja walka przypomina tą z Don Kichote z wiatrakami.
webJ@cob
Przykład

<select name="select">
<option value="a">Test A</option>
<option value="b" selected="selected">Test B</option>
</select>

Zatem:
parametr selected="selected" automatycznie zaznacza w tym wypadku ustawia jako pierwszy element.
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.