Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Problem z zapytaniem SQL (Class)
moto0095
post
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
Post #2





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

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


Cytat
Teoretycznie zrobiles to prawidlowo. Ale
1) $tpl = new TemplatePower('index.tpl');
Czy ten kod masz w glownym pliku czy moze w pliku includowanym
2) $tpl = new TemplatePower('index.tpl');
czy ten kod jest przed wywolaniem funkcji DrawArray a moze po?


Ok, to cały plik index.php :
  1. <?
  2. header("Content-Type:text/html;charset=iso-8859-2");
  3.  
  4. try{
  5. @include_once('connect.php'); // połączenie z bazą
  6. @include_once('class.php'); // klasy: GetMedia, Media, Menu
  7. @include_once("class.TemplatePower.inc.php"); // klasa szablonu
  8.  
  9. $sql = 'SELECT * FROM m_dowcipy';
  10.  
  11. $tpl = new TemplatePower('index.tpl');
  12. $menu = new Menu;
  13. $tpl->prepare();
  14. $media = new GetMedia($sql);
  15.  
  16. $menu->Draw();
  17. $media->Draw();
  18.  
  19. $tpl->printToScreen();
  20.  
  21. } catch(Exception $e) {
  22. echo $e->getMessage();
  23. }
  24. die();
  25. ?>


Ten post edytował moto0095 23.12.2010, 10:48:53
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 10:06