Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP+MySQL] Problem z wyświetlaniem
msdotnet
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 6.01.2009

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


Witam!
Moje pytanie jest następujące. Mam coś takiego na stronie, ale skrypt działa dopiero po odświeżeniu, przed nic nie gra..
Zna ktoś może przyczyne problemu? Dziękuje za wszystkie uwagi
Oto kod :
  1.  
  2. <?php
  3. $conn=mysql_connect("xxx", yyy", "zzz");
  4. if (!$conn) {
  5. die('Nie można się połaczyć: ' . mysql_error());
  6. }
  7. mysql_query('use m69955ma_sowrbin');
  8. $zapyt="select * from art where na_str='glowna' order by id desc limit 5";
  9. $wynik= mysql_query($zapyt);
  10.  
  11. while ($ile = mysql_fetch_array($wynik, $conn)) {
  12. $id1=$ile["id"];
  13. echo "<h3>".$ile["nazwa"]."</h3>";
  14. echo "<i><a href=\"show.php?id=$id1\">".$ile["header"]."</a></i>";
  15. echo "<br><ul><li>Dodał:".$ile["dodal"]."</li></ul>";
  16. }
  17. ?>
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




To nie ma prawa działać bo masz błąd składniowy. Zobacz jak edytor pokolorował kod.


--------------------
Go to the top of the page
+Quote Post
msdotnet
post
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 6.01.2009

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


po odświeżeniu przeglądarki wszystko działa, ale za pierwszym razem nie. czy chodzi o :
  1. #
  2. $zapyt="select * from art where na_str='glowna' order by id desc limit 5";
?
czy starczy zrobic:
  1. $zapyt="select * from art where na_str=/'glowna/' order by id desc limit 5";
#


Ten post edytował msdotnet 1.08.2010, 17:47:16
Go to the top of the page
+Quote Post
krispak
post
Post #4





Grupa: Zarejestrowani
Postów: 250
Pomógł: 55
Dołączył: 27.08.2008

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


W połączeniu z baza nie masz cudzysłowia przy yyy - masz yyy"


--------------------
* * * * * * * * * * * * * * * * * * * * * * * * *
PHP, Laravel, Docker, Docker Compose, Laradock, Redis, JS, React, Vue, CSS, SCSS, Gulp, GIT ... itd..
Go to the top of the page
+Quote Post
msdotnet
post
Post #5





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 6.01.2009

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


sprawdziłem i w po prostu tutaj zapomniałem, w kodzie gra. Tutaj kolejna odsłona. Obydwa działają dopiero po odświeżeniu strony. Przy wpisaniu adresu strony i "enternięciu" nie bangla.
  1. <?php
  2. $conn=mysql_connect("xxx", "yyy", "zzz");
  3. if (!$conn) {
  4. die('Nie można się połaczyć: ' . mysql_error());
  5. }
  6. mysql_query('use m69955ma_sowrbin');
  7. echo "<tr>";
  8. echo "<td width=\"23%\" height=\"165\">";
  9. $zapyt="select id, nazwa, header from art where na_str='galeria' order by id desc limit 1";
  10. $wynik= mysql_query($zapyt);
  11.  
  12. while ($ile = mysql_fetch_array($wynik, $conn)) {
  13. $id1=$ile["id"];
  14. echo $ile["header"];
  15. echo "<p align=\"center\"><b><a href=\"show.php?id=$id1\">".$ile["nazwa"]."</a></b></td>";
  16. }
  17.  
  18. $id2=$id1-1;
  19. $id3=$id2-1;
  20. $id4=$id3-1;
  21. $id5=$id4-1;
  22. $id6=$id5-1;
  23. $id7=$id6-1;
  24. $id8=$id7-1;
  25. $id9=$id8-1;
  26.  
  27.  
  28. echo "<td width=\"24%\" height=\"165\">";
  29. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id2 order by id desc limit 1";
  30. $wynik= mysql_query($zapyt);
  31.  
  32. while ($ile = mysql_fetch_array($wynik, $conn)) {
  33. $idx2=$ile["id"];
  34. echo $ile["header"];
  35. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx2\">".$ile["nazwa"]."</a></b></td>";
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42. echo "<td width=\"24%\" height=\"165\">";
  43. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id3 order by id desc limit 1";
  44. $wynik= mysql_query($zapyt);
  45.  
  46. while ($ile = mysql_fetch_array($wynik, $conn)) {
  47. $idx3=$ile["id"];
  48. echo $ile["header"];
  49. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx3\">".$ile["nazwa"]."</a></b></td>";
  50. }
  51.  
  52.  
  53. echo "</tr><tr>";
  54.  
  55. echo "<td width=\"23%\" height=\"165\">";
  56. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id4 order by id desc limit 1";
  57. $wynik= mysql_query($zapyt);
  58.  
  59. while ($ile = mysql_fetch_array($wynik, $conn)) {
  60. $idx4=$ile["id"];
  61. echo $ile["header"];
  62. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx4\">".$ile["nazwa"]."</a></b></td>";
  63. }
  64.  
  65.  
  66.  
  67. echo "<td width=\"24%\" height=\"165\">";
  68. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id5 order by id desc limit 1";
  69. $wynik= mysql_query($zapyt);
  70.  
  71. while ($ile = mysql_fetch_array($wynik, $conn)) {
  72. $idx5=$ile["id"];
  73. echo $ile["header"];
  74. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx5\">".$ile["nazwa"]."</a></b></td>";
  75. }
  76.  
  77.  
  78. echo "<td width=\"24%\" height=\"165\">";
  79. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id6 order by id desc limit 1";
  80. $wynik= mysql_query($zapyt);
  81.  
  82. while ($ile = mysql_fetch_array($wynik, $conn)) {
  83. $idx6=$ile["id"];
  84. echo $ile["header"];
  85. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx6\">".$ile["nazwa"]."</a></b></td>";
  86. }
  87.  
  88.  
  89. echo " </tr><tr>";
  90.  
  91. echo "<td width=\"23%\" height=\"165\">";
  92. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id7 order by id desc limit 1";
  93. $wynik= mysql_query($zapyt);
  94.  
  95. while ($ile = mysql_fetch_array($wynik, $conn)) {
  96. $idx7=$ile["id"];
  97. echo $ile["header"];
  98. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx7\">".$ile["nazwa"]."</a></b></td>";
  99. }
  100.  
  101.  
  102.  
  103.  
  104. echo "<td width=\"24%\" height=\"165\">";
  105. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id8 order by id desc limit 1";
  106. $wynik= mysql_query($zapyt);
  107.  
  108. while ($ile = mysql_fetch_array($wynik, $conn)) {
  109. $idx8=$ile["id"];
  110. echo $ile["header"];
  111. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx8\">".$ile["nazwa"]."</a></b></td>";
  112. }
  113.  
  114.  
  115. echo "<td width=\"24%\" height=\"165\">";
  116. $zapyt="select id, nazwa, header from art where na_str='galeria' and id=$id9 order by id desc limit 1";
  117. $wynik= mysql_query($zapyt);
  118.  
  119. while ($ile = mysql_fetch_array($wynik, $conn)) {
  120. $idx9=$ile["id"];
  121. echo $ile["header"];
  122. echo "<p align=\"center\"><b><a href=\"show.php?id=$idx9\">".$ile["nazwa"]."</a></b></td>";
  123. }
  124. ?>


naprawde nikt nie ma pomysłu ?
Go to the top of the page
+Quote Post
toel
post
Post #6





Grupa: Zarejestrowani
Postów: 97
Pomógł: 11
Dołączył: 2.02.2010

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


Cytat(msdotnet @ 1.08.2010, 17:52:45 ) *
skrypt działa dopiero po odświeżeniu, przed nic nie gra..


Nic nie gra - tzn. co dokładnie masz w oknie przeglądarki ? Jakiś komunikat ?
A jak nie to jak wygląda źródło strony zwrócone przez przeglądarkę ?
Go to the top of the page
+Quote Post
msdotnet
post
Post #7





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 6.01.2009

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


Na głównej stronie nie zwraca nic. Puste pola, na stronie która pokazuje artykuł wyświetla:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /srv/home/m69955ma/public_html/show.php on line 54
Go to the top of the page
+Quote Post
toel
post
Post #8





Grupa: Zarejestrowani
Postów: 97
Pomógł: 11
Dołączył: 2.02.2010

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


przy każdym zapytaniu do mysql, gdy przypisujesz je do zmiennej, zrób również echo, czyli np.
  1. echo $zapytanie;


Dzięki temu wyświetlisz je wszystkie z zawartością zmiennych typu $id.

Wywołaj sobie każdy z tych selectów bezpośrednio w mysql (np. przez phpmyadmin) i zobacz czy żaden z nich nie zwraca błędu...
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 21.08.2025 - 01:57