Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Tabele o tych samych kolumnach
Szymad
post 5.08.2012, 22:38:12
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 1.12.2011

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


Witam,
mam bazę danych w których jedna z tabel prezentuje się następująco

  1. CREATE TABLE `14_tutorials` (
  2. `ID` int(11) NOT NULL AUTO_INCREMENT,
  3. `Title` text NOT NULL,
  4. `Date` date NOT NULL,
  5. `Desc` text NOT NULL,
  6. `ShortDesc` text NOT NULL,
  7. `Graphic` text NOT NULL,
  8. `Category` int(11) NOT NULL,
  9. `Level` int(11) NOT NULL,
  10. `Price` float NOT NULL,
  11. `Currency` text NOT NULL,
  12. `TotalEarned` float NOT NULL,
  13. `AllowComments` int(11) NOT NULL,
  14. `AllowHands` int(11) NOT NULL,
  15. `AllowSharing` int(11) NOT NULL,
  16. `AllowLiking` int(11) NOT NULL,
  17. `Active` int(11) NOT NULL,
  18. `AllowPayPal` int(11) NOT NULL,
  19. `Lang` text NOT NULL,
  20. `isTEXT` text NOT NULL,
  21. `isAUDIO` text NOT NULL,
  22. `isVID` text NOT NULL,
  23. `TotalDownloads` int(11) NOT NULL DEFAULT '0',
  24. `TotalViewed` int(11) NOT NULL DEFAULT '0',
  25. `TotalHands` int(11) NOT NULL DEFAULT '0',
  26. PRIMARY KEY (`ID`)
  27. )


Takich tabel jest kilka. Chodzi o to żeby pobrać je w jedno zapytanie z którego można przestortować tak aby uzyskać 10 rekordów, dla których `TotalHands` jest największe.
Próbowałem zrobić to w ten sposób, ale mi nie wyszło. Może pomożecie. smile.gif

  1. function getBest($excludeMe){
  2.  
  3.  
  4. $link = mysqli_connect(); //tu jest ok, po prostu nie pokazuje wam danych
  5.  
  6. $all = array();
  7. $counter = 0;
  8. $query = "";
  9. if($excludeMe){ $query = "SELECT * FROM `users` WHERE `ID`<>".$_SESSION['user'][0]; }else{ $query = "SELECT * FROM `users`"; }
  10.  
  11. $run = mysqli_query($link, $query);
  12.  
  13. if($run){
  14.  
  15. while($użytkownik = mysqli_fetch_row($run)){
  16.  
  17. $query = "SELECT `ID`,`Title`,`TotalHands` FROM `$użytkownik[0]_tutorials`";
  18. $run1 = mysqli_query($link,$query);
  19. while($kurs = mysqli_fetch_row($run1)){
  20.  
  21. if($counter>0){
  22. $lastID = count($all) - 1;
  23. if($kurs[2]>$all[$lastID]){
  24.  
  25. $all[$counter][0] = $kurs[0];
  26. $all[$counter][1] = $użytkownik[0];
  27. $all[$counter][2] = $kurs[1];
  28. $all[$counter][3] = $kurs[2];
  29.  
  30. $counter++;
  31. }
  32.  
  33. }else{
  34. $all[$counter][0] = $kurs[0];
  35. $all[$counter][1] = $użytkownik[0];
  36. $all[$counter][2] = $kurs[1];
  37. $all[$counter][3] = $kurs[2];
  38.  
  39.  
  40.  
  41. $counter++;
  42.  
  43. }
  44. }
  45. }
  46.  
  47.  
  48.  
  49. return $all;
  50.  
  51. }else{
  52.  
  53.  
  54. return 1;
  55.  
  56. }
  57. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
irmidjusz
post 5.08.2012, 23:02:09
Post #2





Grupa: Zarejestrowani
Postów: 279
Pomógł: 60
Dołączył: 25.02.2012

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


http://www.mysqltutorial.org/sql-union-mysql.aspx


--------------------
there is much to be learned
Go to the top of the page
+Quote Post
Szymad
post 6.08.2012, 11:55:34
Post #3





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 1.12.2011

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


Dziękuje smile.gif
Go to the top of the page
+Quote Post

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: 14.08.2025 - 05:29