Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php & mysql] Newsy i Komenty
Forum PHP.pl > Forum > Gotowe rozwiązania > Skrypty obsługi baz danych
Depor
Mam taki kod, i nie wiem czemu nie chce mi zliczać ilości komentarzy??


  1. <?php
  2. $ilosckom = mysql_fetch_row(mysql_query(&#092;"select COUNT(*) from komentarze where news = '$_GET[nr]'\"));
  3. ?>



  1. <?php
  2. if ($nr>0) {
  3. $temp=$_GET['nr'];
  4. $wynik = mysql_query (&#092;"select * from news WHERE nr='$nr';\")
  5. or die(&#092;"Zapytanie niepoprawne\");
  6. $ilosc = mysql_num_rows($wynik);
  7. if ($ilosc==1) {
  8. $rekord = mysql_fetch_array ($wynik);
  9.  
  10. $ilosckom = mysql_fetch_row(mysql_query(&#092;"select COUNT(*) from komentarze where news = '$rekord[0]'\"));
  11.  
  12.  
  13. echo &#092;"
  14. <table width=570 border=0 cellpadding=0 cellspacing=0>
  15. <tr>
  16. <td width=570 height=24 align=left background=gfx/news/1.gif class=tekst2>
  17. &nbsp;&nbsp;&nbsp;Tytuł:&nbsp<b>&#092;".$rekord[2].\"</b>
  18. </td>
  19. </tr>
  20. <tr>
  21. <td valign=top>
  22. <table width=100% border=0 cellpadding=0 cellspacing=0>
  23. <tr>
  24. <td width=570 style=padding:7px valign=top align=left background=gfx/news/2.gif class=tekst>
  25. <img src=gfx/news/5.gif align=left>
  26. &#092;".$rekord[3].\"&nbsp;\".$rekord[4].\"
  27. <br />
  28. <br />
  29. </td>
  30. </tr>
  31. <tr>
  32. <td height=16 valign=top>
  33. <table width=100% border=0 cellpadding=0 cellspacing=0>
  34. <tr>
  35. <td width=364 height=16 valign=top><img src=gfx/news/3.gif width=364 height=16></td>
  36. <td width=206 height=16 valign=middle background=gfx/news/4.gif align=center class=tekst2>
  37. Dodał: <&#092;".$rekord[6].\" href=forum/profile.php?mode=viewprofile&u=\".$rekord[7].\">\".$rekord[5].\"</a>&nbsp; komentarze[\".$ilosckom[0].\"]
  38. </td>
  39. </tr>
  40. </table>
  41. </td>
  42. </tr>
  43. </table>
  44. </table>&#092;";
  45.  
  46. // news wydrukowany
  47. //if ( defined('logged_in') ) {
  48. $wynik = mysql_query(&#092;"SELECT comment, time, author, ip, user, kolor user FROM komentarze WHERE ne
    w
  49. ='$_GET[nr]' ORDER BY time DESC\");
  50. echo \"<center>\";
  51. while(list($comment, $time, $author, $ip, $user, $kolor) = mysql_fetch_array($wynik)) {
  52. $comment = nl2br(htmlspecialchars($comment));
  53.  
  54. $author = \"<a \".$kolor.\" href='forum/profile.php?mode=viewprofile&u=\".$user.\"'>$author</a>\";
  55.  
  56. $ip = nl2br(htmlspecialchars($ip));
  57. print \"<br><table class=tekst width=300>n\";
  58. print \"<tr>n\";
  59. print \"<td align=left width=150 bgColor=black>&nbsp;\".$author.\"</span></td>n\";
  60. print \"<td align=right width=150 bgColor=black>\".$time.\"&nbsp;</td></tr>n\";
  61. print \"<tr><td width=300 bgColor=black colspan='2' align=justify>&nbsp;$comment&nbsp;</td></tr>n\";
  62. print \"<tr><td width='300' bgColor=black colspan='2'><center>$ip</center></td></tr>n\";
  63. print \"</table>n\";
  64. }
  65. print \"</center>\";
  66. echo \"<div align='center'>
  67. <div align=center>
  68. <form action='dodaj_strona.php' method='post' name='dodaj_strona'>
  69. </div>
  70. <table class=menu border=0 cellpadding=0 cellspacing=0>
  71. <tr valign=top>
  72. <td class='kom'>
  73. <p align=center>
  74. <textarea name='comment' rows=10 cols=35>Twój komentarz...</textarea>
  75. </p>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td><p align=center><input type=submit value='Dodaj'>
  80. <input type='hidden' name='nr' value='$_GET[nr]'></p></td>
  81. </tr>
  82. </table>
  83. </form>
  84. </div>&#092;";
  85. //} else {
  86. //echo \"<br><br><span class=tekst>Aby przeglądać i dodawać komentarze musisz się zalogować!</span>\"; }
  87. } else {
  88. print &#092;"Nie ma newsa o podanym numerzen\";
  89. }
  90. } else {
  91.  
  92.  
  93.  
  94.  
  95. $wynik = mysql_query (&#092;"select * from news order by nr desc\")
  96. or die(&#092;"Zapytanie niepoprawne\");
  97.  
  98. while ($rekord = mysql_fetch_array ($wynik)) {
  99. $ilosckom = mysql_fetch_row(mysql_query(&#092;"select COUNT(*) from komentarze where news = '$_GET[nr]'\"));
  100.  
  101. echo &#092;"
  102. <table width=570 border=0 cellpadding=0 cellspacing=0>
  103. <tr>
  104. <td width=570 height=24 align=left background=gfx/news/1.gif class=tekst2>
  105. &nbsp;&nbsp;&nbsp;Tytuł:&nbsp<b>&#092;".$rekord[2].\"</b>
  106. </td>
  107. </tr>
  108. <tr>
  109. <td valign=top>
  110. <table width=100% border=0 cellpadding=0 cellspacing=0>
  111. <tr>
  112. <td width=570 style=padding:7px valign=top align=left background=gfx/news/2.gif class=tekst>
  113. <img src=gfx/news/5.gif align=left>
  114. &#092;".$rekord[3].\"
  115. <br><br>
  116. <i><p align=left><class=a2 href=&#092;"strona.php?nr=\".$rekord[0].\"\">Więcej...</i></p>
  117. </td>
  118. </tr>
  119. <tr>
  120. <td height=16 valign=top>
  121. <table width=100% border=0 cellpadding=0 cellspacing=0>
  122. <tr>
  123. <td width=364 height=16 valign=top><img src=gfx/news/3.gif width=364 height=16></td>
  124. <td width=206 height=16 valign=middle background=gfx/news/4.gif align=center class=tekst2>
  125. Dodał: <&#092;".$rekord[6].\" href=forum/profile.php?mode=viewprofile&u=\".$rekord[7].\">\".$rekord[5].\"</a>&nbsp; komentarze[\".$ilosckom[0].\"]
  126. </td>
  127. </tr>
  128. </table>
  129. </td>
  130. </tr>
  131. </table>
  132. </table><br>&#092;";
  133. }
  134.  
  135. }
  136. ?>
Yarecki
Spróbuj tak:
  1. <?php
  2.  
  3. $ilosckom = mysql_fetch_row( mysql_query( 'select COUNT(*) FROM komentarze where news = ' . $_GET['nr'] ) );
  4.  
  5. ?>

możesz jeszcze dodać or die( mysql_error() ) po funkcjach mysql_*.
Depor
Hmm , nie działa??
Ale dlaczego?
Wie ktoś moze przypadkiem czemu serwer gry-online są takie gówniane?? I nic na nich nie działa?
zbig13
Może spróbuj z mysql_num_rows();
  1. <?php
  2.  
  3. $ilosckom = mysql_num_rows(mysql_query(&#092;"select * from komentarze where news = {$_GET['nr']}\"));
  4.  
  5. ?>
sf
Cytat(Depor @ 2005-02-18 17:33:50)
Wie ktoś moze przypadkiem czemu serwer gry-online są takie gówniane?? I nic na nich nie działa?

Patrząc na Twój bajzel w kodzie to ten epitem kierowałbym w stronę Twoich umiejętności programistycznych tiredsmiley.gif
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.