Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Pobranie dwóch tabel
tenloginjestzaje...
post
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 1
Dołączył: 20.07.2014

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


Witam mam problem, nie wiem jak pobrać dwie tabele, do pobrania jednej używam:
  1. $query1 = mysql_query("SELECT DISTINCT `tag` FROM `comments`");
  2. while($row = mysql_fetch_assoc($query1)){echo '';}


Potrzebuje jeszcze pobrać:

  1. $query1 = mysql_query("SELECT DISTINCT `tag` FROM `tags`");
  2. while($row = mysql_fetch_assoc($query1)){echo '';}


Tak żeby w jednym echo były wniki z dwóch tabel. Dziękuje
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


db.class.php
  1. <?php
  2. class MySQL{
  3.  
  4. var $m;
  5.  
  6. var $result;
  7. private $server;
  8. private $user;
  9. private $password;
  10. private $database;
  11.  
  12. public $errors = array();
  13.  
  14. public function __construct($server, $user, $password, $database){
  15. $this->server = $server;
  16. $this->user = $user;
  17. $this->password = $password;
  18. $this->database = $database;
  19.  
  20. $this->m = mysql_connect($this->server, $this->user, $this->password);
  21.  
  22. $this->query('SET charset utf8');
  23.  
  24. $this->errors = array(mysql_errno($this->m), mysql_error($this->m));
  25.  
  26. }
  27.  
  28. public function query($sql){
  29.  
  30. $this->result = mysql_db_query($this->database, $sql, $this->m);
  31.  
  32. $this->errors = array(mysql_errno($this->m), mysql_error($this->m));
  33.  
  34. }
  35.  
  36. public function num_rows(){
  37.  
  38. return mysql_num_rows($this->result);
  39.  
  40. }
  41.  
  42. public function affected_rows(){
  43.  
  44. return mysql_affected_rows($this->m);
  45.  
  46. }
  47.  
  48. public function sh_result(){
  49.  
  50. return $this->result;
  51.  
  52. }
  53.  
  54. public function id(){
  55.  
  56. return mysql_insert_id($this->m);
  57.  
  58. }
  59.  
  60. public function escape($string){
  61.  
  62. return mysql_real_escape_string(trim($string), $this->m);
  63.  
  64. }
  65.  
  66. public function fetch_array(){
  67.  
  68. return mysql_fetch_array($this->result, MYSQL_ASSOC);
  69.  
  70. }
  71.  
  72. public function result(){
  73.  
  74. return mysql_result($this->result, 0);
  75.  
  76. }
  77.  
  78. public function __destruct(){
  79.  
  80. $this->errors = array(mysql_errno($this->m), mysql_error($this->m));
  81.  
  82. //mysql_close($this->m);
  83.  
  84. }
  85.  
  86. }


i później:
  1. $mysql1 = new MySQL('serwer','uzytkownik', 'haslo', 'nazwa_bazy');
  2. $mysql2 = new MySQL('serwer2','uzytkownik2', 'haslo2', 'nazwa_bazy2');


Ten post edytował kapslokk 4.07.2015, 21:46:35
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: 12.10.2025 - 02:01