Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP + MySQL] Sortowanie danych pobranych z bazy danych
henio
post
Post #1





Grupa: Zarejestrowani
Postów: 237
Pomógł: 1
Dołączył: 15.10.2004
Skąd: Lublin

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


Mam pewien kłopot z posortowaniem. Otóż mam tabele forum_topic i forum_post i chce posortowac wszystkie tematy malejąco po ostatnim dodanym poscie w danym temacie.
Fragment kodu:
  1. <?php
  2. elseif(@$_GET['id_forum_watek'] && @$_GET['id_forum_dzial'])
  3. {
  4. naglowekforum("Zobacz forum numer ".@$_GET['id_forum_dzial']."");
  5. echo "<a href='index.php?id_forum_dzial=".@$_GET['id_forum_dzial']."&id_forum_watek=".@$_GET['id_forum_watek']."&czynnosc=utworz_topic'>Utwórz nowy temat</a>\n";
  6. echo "<table align='center' width='90%' border='1' style='border-collapse: collapse'><tr bgcolor='#CCCFF'>";
  7. echo "<th colspan='2'>Ważne tematy</th><th width='50'>Posty</th><th width='100'>Autor</th><th width='150'>Ostatni post</th>\n";
  8. echo "</table><br />\n";
  9. echo "<table align='center' width='90%' border='1' style='border-collapse: collapse'><tr bgcolor='#CCCFF'>";
  10. echo "<th colspan='2'>Tematy</th><th width='50'>Posty</th><th width='100'>Autor</th><th width='150'>Ostatni post</th>\n";
  11.  
  12. $query4 = "SELECT * FROM forum_topic WHERE id_forum_dzial = '".@$_GET['id_forum_dzial']."' AND id_forum_watek='".@$_GET['id_forum_watek']."'";
  13. $result4 = mysqli_query($mysql, $query4) or die('zapytanie: '.$query4.'---blad:'.mysqli_error($mysql));
  14.  
  15. while ($row4 = mysqli_fetch_assoc($result4))
  16. {
  17. echo "<tr><td>=></td><td width='60%'><a href='index.php?id_forum_dzial=".@$_GET['id_forum_dzial']."&id_forum_watek=".@$_GET['id_forum_watek']."&id_forum_topic=".$row4['id_forum_topic']."'>".$row4['tytul']."</a><br />".$row4['podtytul']."</td><td>";
  18.  
  19. $query8 = "SELECT * FROM forum_post WHERE id_forum_topic = '".$row4['id_forum_topic']."'";
  20. $result8 = mysqli_query($mysql, $query8) or die('zapytanie: '.$query8.'---blad:'.mysqli_error($mysql));
  21. $liczba_postow = mysqli_num_rows($result8);
  22. echo "".$liczba_postow."</td><td>";
  23.  
  24. $query5 = "SELECT nick FROM forum_uzytkownicy WHERE id_forum_user = '".$row4['id_forum_user']."'";
  25. $result5 = mysqli_query($mysql, $query5) or die('zapytanie: '.$query5.'---blad:'.mysqli_error($mysql));
  26. while ($row5 = mysqli_fetch_assoc($result5))
  27. {
  28. echo "".$row5['nick']."</td><td>";
  29. }
  30.  
  31. $query6 = "SELECT data_powstania, id_forum_user FROM forum_post WHERE id_forum_topic =
     '"
    .$row4['id_forum_topic']."' ORDER BY data_powstania DESC LIMIT 0,1";
  32. $result6 = mysqli_query($mysql, $query6) or die('zapytanie: '.$query6.'---blad:'.mysqli_error($mysql));
  33. while ($row6 = mysqli_fetch_assoc($result6))
  34. {
  35. echo "".$row6['data_powstania']."<br />";
  36. $query7 = "SELECT nick FROM forum_uzytkownicy WHERE id_forum_user = '".$row6['id_forum_user']."'";
  37. $result7 = mysqli_query($mysql, $query7) or die('zapytanie: '.$query7.'---blad:'.mysqli_error($mysql));
  38. while ($row7 = mysqli_fetch_assoc($result7))
  39. {
  40. echo "".$row7['nick']."</td>";
  41. }
  42. }
  43. echo "</tr>\n";
  44. }
  45. echo "</table>\n";
  46. }
  47. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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 - 13:54