Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Smarty] Generowanie kilku kategorii
GameMaker
post 9.09.2011, 14:16:23
Post #1





Grupa: Zarejestrowani
Postów: 149
Pomógł: 2
Dołączył: 31.01.2010
Skąd: Konstancin-Jeziorna

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


Witajcie ! mam problem z wygenerowaniem kilku kategorii dla danego artykułu.

Mój kod :
  1.  
  2. if (! defined ( 'Movie_CMS' )) {
  3. header("HTTP/1.0 404 Not Found");
  4. }
  5. require_once('./classes/Pager.class.php');
  6.  
  7.  
  8. $zz = $db->query("Select * from mpa_movies");
  9. $licz = $db->num_rows($zz);
  10.  
  11. try{
  12. $pager = new Pager('page','http://localhost/filmy/#PAGE#.html');
  13. $pager->SetTotalRecords($licz);
  14. $pager->SetRecordsPerPage(10);
  15. $pager->Make(true);
  16. $pag = $pager->Render();
  17. $start = $pager->GetIndexRecordStart();
  18. $end = $pager->GetIndexRecordEnd();
  19. }
  20. catch (Exception $e) {
  21. echo $e->getMessage();
  22. }
  23.  
  24.  
  25.  
  26. $zapytanie = 'Select * from mpa_movies order by data DESC limit '.$start.','.($end - $start + 1);
  27. $q = $db->query($zapytanie);
  28. $arr = array();
  29. $i = 0;
  30. while($row = $db->fetch_array($q))
  31. {
  32.  
  33. $arr[] = $row['id'];
  34. $arr[] = $row['name'];
  35. $arr[] = $row['data'];
  36. $arr[] = $row['views'];
  37. $arr[] = $row['poster'];
  38. $arr[] = $row['describe'];
  39. $arr[] = $row['easy_url'];
  40. $arr[] = $row['comnum'];
  41. $arr[] = $row['autor'];
  42.  
  43. $c = explode(',',$row['category_id']);
  44. $c = array_filter($c);
  45. $categ = "";
  46. foreach($c as $cc)
  47. {
  48. $categ.= cat($cc);
  49.  
  50.  
  51. }
  52.  
  53. $arr[] = $categ;
  54.  
  55.  
  56.  
  57.  
  58. }
  59. print_r($arr);
  60. $smarty->assign('row',$arr);
  61. $smarty->assign('pager',$pag);
  62.  
  63.  
  64.  



funkcja
  1. function cat($id)
  2. {
  3. global $db;
  4.  
  5. $r = $db->query("Select * from mpa_categories where id ='$id'");
  6.  
  7. if($db->num_rows($r) > 0)
  8. {
  9. $r = $db->fetch_array($r);
  10.  
  11. $category = "<a href='/category/$r[alt_name]'>$r[name]</a>,";
  12.  
  13. }else{
  14.  
  15. $category = "Brak kategorii !,";
  16. }
  17.  
  18. return $category;
  19. }
  20.  



Plik tpl

  1.  
  2. {foreach $row as $con}
  3.  
  4. <div class="content">
  5. <div class="content-headline">{$con.title}</div>
  6. <div class="content-info">Kategoria: <b>{$con.cats}</b> | Wy&#347;wietleń: <b>{$con.views}</b> | Komentarzy <strong>{$con.comnum}</strong> | Doda&#322 : {$con.autor}</div>
  7. <div class="content-poster"><img src="{$con.poster}" alt="2" /></div>
  8. <div class="content-description">{$con.describe}</div>
  9. <div class="content-button">
  10. <div class="button-download"><a href="http://localhost/film/{$con.id}-{$con.easy_url}.html">Ogl&#261daj bez limitu</a></div>
  11. <div class="button-watch"><a href="/link">Ogl&#261daj</a></div>
  12. </div>
  13. </div>
  14. {/foreach}
  15.  
  16. {include file="paginator.tpl"}
  17.  





--------------------
Movie CMS v 0.1 - Postęp 37 45 49 53 69 %
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:15