Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlanie wyników z MySQL
cholew
post 31.01.2007, 16:26:25
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 5.01.2007

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


WItam, mam problem z wyświtlaniem wyników z bazy MySQL.
Chodzi o to ze na 1 stronie wyswietla sie 10 wyników, na 2 jest 20 a na ktorejs tam jest nawet 30, i niektore sie powtarzaja.
Niżej zamieszczam kod, moze ktos mi powie co w nim jest nie tak? smile.gif

  1. <?php
  2. if(isset($_GET['typ'])) {
  3. $typ = '`typ` = ' . (int) $_GET['typ'];
  4. }else{
  5. $typ = "((`typ` >= 1 and `typ` <= 4) or (typ = '15') or (typ = '16') or (typ = '17'))";
  6. }
  7. //$typ = (isset($_GET['typ']) ? '`typ` = ' . (int) $_GET['typ'] : '((`typ` >= 1 and `typ` <= 4) or (typ = '15'))');
  8. $cat = (isset($_GET['cat']) ? ' and `category` = ' . (int) $_GET['cat'] : '');
  9. $order = '';
  10. if ($_GET['top'] == 1)
  11. {
  12. $order = ' order by `ocena` desc';
  13. }
  14. elseif ($_GET['last'] == 1)
  15. {
  16. $order = ' order by `added` desc';
  17. }
  18. $res = mysql_query('select * from `stuff` where ' . $typ . $cat);
  19. // ilosć trafień
  20. $hits = mysql_num_rows($res);
  21. $res = mysql_query('select * from `stuff` where ' . $typ . $cat . $order . ' order by added desc limit ' . ((int) $_GET['currentpage'] * 1) . ', ' . ((int) $_GET['currentpage'] * 10 + 10));
  22. if ($hits == 0)
  23. {
  24. echo '<center>Ta kategoria jest pusta.</center>';
  25. }
  26. else
  27. {
  28. while ($row = mysql_fetch_assoc($res))
  29. {
  30. if($row['added']>0)
  31. $date = sprintf('<img src="ikonki/dodano.jpg">Dodano: %s godzina %s<br />', date('Y.m.d', $row['added']), date('H:i:s', $row['added']));
  32. else
  33. $date = (string) '';
  34. $comments_count = (int) 0;
  35. $query = sprintf("SELECT COUNT(*) AS CommentsCount FROM komentarze WHERE stuff='%d'", $row['id']);
  36. $comments = mysql_query($query);
  37. if($comments) {
  38. $record = mysql_fetch_assoc($comments);
  39. $comments_count = $record['CommentsCount'];
  40. mysql_free_result($comments);
  41. }
  42. if($row['miniaturka']!='') { 
  43. $image = sprintf('<img src="%s" alt="%s" class="icon"align="right"width="160px"height="120px"border="2" />', $row['miniaturka'], $row['title']);
  44. } else {
  45. $image = '';
  46. }
  47. if(isset($categories[$row['category']]))
  48. $cat = sprintf("%s: ", $categories[$row['category']]);
  49. else
  50. $cat = (string) '';
  51. printf('<table width="420" bgcolor="#F3F3F3" style="margin-bottom:12px;font-family:verdana;font-size:12px;"><tr><td style="text-align:left; clear:both; padding:0 4px;">%s <b>%s</b><a href="index.php?page=display&id=%d" class="stufflink"style="font-weight:bold;">%s</a><br />%s<img src="ikonki/wykres.jpg">Ocena: %d<br /><img src="ikonki/wykres.gif">Wyswietlen: %d<br /><img src="ikonki/trabka.gif">Komentarzy: %d<br /><img src="ikonki/info.gif">Zasugerował: %s</td></tr></table>',
  52. $image,
  53. $cat, $row['id'], $row['tytul'],
  54. $date,
  55.  
  56. $row['ocena'], $row['counter'],
  57. $comments_count, $row['login']);
  58. }
  59. }
  60.  
  61. echo '<center>';
  62. /********* NUMEROWANIE *********/
  63. if ($hits !== 0)
  64. {
  65. $temp = min((int) $_GET['currentpage'] + 50, ceil((float) $hits / 9.0));
  66. print('Strona: ');
  67. for ($i = max((int) $_GET['currentpage'] - 50, 0); $i < $temp; $i++)
  68. {
  69.  print("<a href="index.php?page=list1&currentpage=" . $i . "&cat=" . $_GET['cat'] . "">" . ($i+1) . "</a> ");
  70.  
  71. }
  72. }
  73. /*******************************/
  74. echo '</center>';
  75. ?>


Ten post edytował cholew 31.01.2007, 16:41:03
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 Wersja Lo-Fi Aktualny czas: 13.08.2025 - 23:13