Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Problem z zapytaniem SQL (Class)
moto0095
post 21.12.2010, 14:30:06
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Witam.
Ostatnio zrobiłem sobie taką klasę do pobierania materiałów z bazy i mam problem z "podawaniem" zapytania:
  1. class GetMedia {
  2. protected $array = array();
  3. public $sql;
  4.  
  5. public function GetMedia($sql) {
  6. $this->sql = $sql;
  7. }
  8.  
  9. function __construct() {
  10. global $db;
  11. $res = $db->query($this->sql); // tu mi się wyświetli prośbę o podanie zapytania.
  12. while($row = $res->fetch_array()) {
  13. $this->array[] = $row;
  14. }
  15. }
  16.  
  17. public function Draw(){
  18. return $this->array;
  19. }
  20. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
moto0095
post 23.12.2010, 11:04:55
Post #2





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Działa, ale miałem durny błąd:
  1. foreach($this->array as $value){
  2. $tpl->newBlock('media');
  3. $tpl->assign(array('id' => $r['id'],
  4. 'nick' => $r['nick'],
  5. 'kategoria' => $r['kategoria'])
  6. );
  7. }

W foreach miałem "this->array as $value" a potem $r plus
  1. global $tpl;
  2. $tpl = new TemplatePower('index.tpl');


i działa. WIELKIE DZIĘKI I WESOŁYCH ŚWIĄT RYCZĘ exclamation.gif
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: 29.06.2025 - 09:34