Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Błąd z pobieraniem z bazy
Forum PHP.pl > Forum > Przedszkole
licha
Po raz kolejny php mnie pokonało i chyba po raz kolejny ta sama rzecz a mianowicie chodzi mi o pobieranie z bazy i nie wiem czemu nie działa
zapytanie poprawne w phpmyadmin sie to co chcę wyszukuje a tu nie umi !
mój kod to :
  1. require('conn.php');
  2. $trenmiej = mysql_query("SELECT `id` FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  3. while ($trenmiejsce = mysql_fetch_array($trenmiej, MYSQL_NUM)) {
  4. }
  5. $trenm=$trenmiejsce[0];
  6.  
  7. print("$trenm");
tolomei
W jakim celu wstawiasz pętlę która nic nie robi?
Co chcesz tym osiągnąć?

Co ogólnie chcesz pobrać?
Pierwszy rekord z bazy?
jaslanin
  1. require('conn.php');
  2. $trenmiej = mysql_query("SELECT `id` FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  3. while ($trenmiejsce = mysql_fetch_array($trenmiej, MYSQL_NUM)) {
  4. $trenm=$trenmiejsce[0];
  5.  
  6. print("$trenm");
  7. }


tak powinno działać, mysql_fetch_array przesuwa wewnętrzny kursor danych dla zmiennej $trenmiejsce i dlatego na zewnątrz pętli nie jest dostępna zmienna $trenmiejsce
licha
1.ja ten kod dostałem od kogoś i w starym projekcie mi to działało i się nie zgłębiałem czy jest dobrze
2. chcę pobrać id wyniku gdzie te 3 parametry się zgadzają czyli 1 miejsce na 1 sesji w 1 wyścigu zamiast id w głównym kodzie mam 'kto'
3. nie pobieram 1 rekordu z bazy bo zamiast 1 miejsce może być np 16 miejsce

dokładnie potrzebuje to do wyników z gp w lidze w f1
tolomei
Jeśli chodzi o pobranie i wyświetlenie wszystkich wyników spełniających warunek - tak jak kolega jaslanin napisał.

Jeśli chcesz pobrać tylko jeden wynik - wtedy piszesz tak:

  1. require('conn.php');
  2. $trenmiej = mysql_query("SELECT `id` FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  3. $trenmiejsce = mysql_fetch_array($trenmiej, MYSQL_NUM);
  4. print($trenmiejsce[0]);
licha



  1. $trenmiej1 = mysql_query("SELECT `kto` FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  2. while ($trenmiejsce1 = mysql_fetch_array($trenmiej1, MYSQL_NUM)) {
  3.  
  4. $trencza1 = mysql_query("SELECT `kto` FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  5. while ($trenczas1 = mysql_fetch_array($trencza1, MYSQL_NUM)) {
  6.  
  7.  
  8. $team1 = mysql_query("SELECT `team` FROM `zawodnicy` WHERE `zawodnik` = '$trenmiejsce1' ");
  9. while ($teams1 = mysql_fetch_array($team1, MYSQL_NUM)) {
  10.  
  11. ...
  12. echo "<tr>";
  13. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 1 </td>
  14. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $tremiejsce1[0] </td>
  15. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams1[0] </td>
  16. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas1[0] </td>";
  17. echo "</tr>";
  18. ...
  19. }
  20. }
  21. }



zgodnie z radą } dałem na koniec i sie nie wyświetla w tabelach ;/
próbowałem też taK
  1. $t=$trenmiejsce1[0]
  2. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 1 </td>
  3. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $t </td>

ale też się nie wyświetla sad.gif
tolomei
Nie no tak to nie zadziała.

Narysuj tabelkę jaką chcesz stworzyć z przykładowymi danymi.
Czy to ma być tylko jedna tabelka czy wiele tabelek?
Opisz co to ma być.
licha
  1. <tr>
  2. <td width=\"200\" height=\"20\" background=\"/dok.png\"> LP </td>
  3. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> Nazwa Gracza </td>
  4. <td width=\"200\" height=\"20\" background=\"/dok.png\"> Team </td>
  5. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> Czas </td>
  6. </tr>
  7. <tr>
  8. <td width=\"200\" height=\"20\" background=\"/dok.png\"> 1 </td>
  9. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce1 </td>
  10. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams1 </td>
  11. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas1 </td>
  12. </tr>


tylko że trochę dłuższa
ps wiem że tak to nie działa
MlodyJNTR
Może to zadziała ? w te miejsca '.$tre[' (nazwa tabeli) '].'

  1. <?php
  2. $trenmiej = mysql_query("SELECT * FROM `wyscigi` WHERE `miejsce` = '1' and `sesja` = '1' and `gp` = '1'");
  3.  
  4. while($tre = mysql_fetch_assoc($trenmiej)) {
  5.  
  6. <table>
  7. <tr>
  8. <td width="200" height="20" background="/dok.png"> LP </td>
  9. <td width="200" height="20" background="/dok1.png"> Nazwa Gracza </td>
  10. <td width="200" height="20" background="/dok.png"> Team </td>
  11. <td width="200" height="20" background="/dok2.png"> Czas </td>
  12. </tr>
  13.  
  14. <tr>
  15. <td width="200" height="20" background="/dok.png"> '.$tre['id'].' </td>
  16. <td width="200" height="20" background="/dok1.png"> '.$tre['trenmiejsce'].' </td>
  17. <td width="200" height="20" background="/dok.png"> '.$tre['teams'].' </td>
  18. <td width="200" height="20" background="/dok2.png"> '.$tre['trenczas'].' </td>
  19. </tr>
  20. </table>
  21. ';
  22.  
  23. }
  24. ?>
licha
trochę się chyba nie zrozumieliśmy wklejam całą tabelę :

  1. echo "<table>";
  2. echo "<tr>";
  3. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> LP </td>
  4. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> Nazwa Gracza </td>
  5. <td width=\"200\" height=\"20\" background=\"/dok.png\"> Team </td>
  6. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> Czas </td>";
  7. echo "</tr>";
  8. echo "<tr>";
  9. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 1 </td>
  10. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $remiejsce </td>
  11. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams1 </td>
  12. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas1 </td>";
  13. echo "</tr>";
  14. echo "<tr>";
  15. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 2 </td>
  16. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce2 </td>
  17. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams2 </td>
  18. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas2 </td>";
  19. echo "</tr>";
  20. echo "<tr>";
  21. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 3 </td>
  22. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce3 </td>
  23. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams3 </td>
  24. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas3 </td>";
  25. echo "</tr>";
  26. echo "<tr>";
  27. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 4 </td>
  28. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce4 </td>
  29. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams4 </td>
  30. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas4 </td>";
  31. echo "</tr>";
  32. echo "<tr>";
  33. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 5 </td>
  34. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce5 </td>
  35. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams5 </td>
  36. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas5 </td>";
  37. echo "</tr>";
  38. echo "<tr>";
  39. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 6 </td>
  40. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce6 </td>
  41. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams6 </td>
  42. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas6 </td>";
  43. echo "</tr>";
  44. echo "<tr>";
  45. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 7 </td>
  46. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce7 </td>
  47. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams7 </td>
  48. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas7 </td>";
  49. echo "</tr>";
  50. echo "<tr>";
  51. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 8 </td>
  52. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce8 </td>
  53. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams8 </td>
  54. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas8 </td>";
  55. echo "</tr>";
  56. echo "<tr>";
  57. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 9 </td>
  58. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce9 </td>
  59. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams9 </td>
  60. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas9 </td>";
  61. echo "</tr>";
  62. echo "<tr>";
  63. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 10 </td>
  64. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce10 </td>
  65. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams10 </td>
  66. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas10 </td>";
  67. echo "</tr>";
  68. echo "<tr>";
  69. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 11 </td>
  70. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce11 </td>
  71. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams11 </td>
  72. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas11 </td>";
  73. echo "</tr>";
  74. echo "<tr>";
  75. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 12 </td>
  76. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce12 </td>
  77. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams12 </td>
  78. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas12 </td>";
  79. echo "</tr>";
  80. echo "<tr>";
  81. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 13 </td>
  82. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce13 </td>
  83. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams13 </td>
  84. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas13 </td>";
  85. echo "</tr>";
  86. echo "<tr>";
  87. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 14 </td>
  88. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce14 </td>
  89. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams14 </td>
  90. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas14 </td>";
  91. echo "</tr>";
  92. echo "<tr>";
  93. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 15 </td>
  94. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce15 </td>
  95. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams15 </td>
  96. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas15 </td>";
  97. echo "</tr>";
  98. echo "<tr>";
  99. echo " <td width=\"200\" height=\"20\" background=\"/dok.png\"> 16 </td>
  100. <td width=\"200\" height=\"20\" background=\"/dok1.png\"> $trenmiejsce16 </td>
  101. <td width=\"200\" height=\"20\" background=\"/dok.png\"> $teams16 </td>
  102. <td width=\"200\" height=\"20\" background=\"/dok2.png\"> $trenczas16 </td>";
  103. echo "</tr>";
  104. echo "</table>";
MlodyJNTR
yyyy ... po co tak lepiej wpisać

  1. <?php
  2. $trenmiej = mysql_query("SELECT * FROM `wyscigi` LIMIT 16");
  3.  
  4. echo '<table>
  5. <tr>
  6. <td width="200" height="20" background="/dok.png"> LP </td>
  7. <td width="200" height="20" background="/dok1.png"> Nazwa Gracza </td>
  8. <td width="200" height="20" background="/dok.png"> Team </td>
  9. <td width="200" height="20" background="/dok2.png"> Czas </td>
  10. </tr>';
  11.  
  12. while($tre = mysql_fetch_assoc($trenmiej)) {
  13. <tr>
  14. <td width="200" height="20" background="/dok.png"> '.$tre['id'].' </td>
  15. <td width="200" height="20" background="/dok1.png"> '.$tre['trenmiejsce'].' </td>
  16. <td width="200" height="20" background="/dok.png"> '.$tre['teams'].' </td>
  17. <td width="200" height="20" background="/dok2.png"> '.$tre['trenczas'].' </td>
  18. </tr>
  19. ';
  20. }
  21.  
  22. echo '</table>';
  23. ?>


i wyświetli się 16 wyników
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.