Not logged in. · Lost password · Register
Forum: PHP & Datenbanken Technischer Support RSS
[gelöst] Frage wg. Sortierung
Noobfrage
a1Pha #1
User title: wayne?
Member since Aug 2006 · 6 posts · Location: Düsseldorf / NRW / Germany
Group memberships: Mitglieder
Show profile · Link to this post
Subject: [gelöst] Frage wg. Sortierung
huhu zusammen,

habe ein kleines problem:

ich entwickle für mein internetradio eine neue internetseite (http://m00.a1pha.de, die alte http://www.a1pha.de war zu lame ;) ).

auf der neuen page soll es ein charts-system geben, d.h.:
ein user gibt einen vote ab, und einmal täglich werden die votes umgerechnet in plätze.
nun bin ich gerade dabei, am cronscript zu verzweifeln, welches die votes in plätze umrechnet und die änderungen in die datenbank einträgt.

  1. --
  2. -- Table structure for table `****_charts`
  3. --
  4.  
  5. CREATE TABLE `****_charts` (
  6.  `id` int(11) NOT NULL AUTO_INCREMENT,
  7.  `platz` int(3) NOT NULL DEFAULT '0',
  8.  `titel` text NOT NULL,
  9.  `votes` smallint(6) NOT NULL DEFAULT '0',
  10.  PRIMARY KEY  (`id`)
  11. ) TYPE=MyISAM AUTO_INCREMENT=23 ;
  12.  
  13. --
  14. -- Dumping data for table `****_charts`
  15. --
  16.  
  17. INSERT INTO `****_charts` (`id`, `platz`, `titel`, `votes`) VALUES (3, 1, 'Pohlmann - Wenn jetzt Sommer wär', 4),
  18. (4, 2, 'Mando Diao - Long before rock''n''roll', 1),
  19. (5, 3, 'Depeche Mode - John the revelator', 0),
  20. (6, 4, 'Sportfreunde Stiller - Eine Liebe, die nie endet', 0),
  21. (7, 5, 'Madonna - Get together', 0),
  22. (8, 6, 'Reamonn - Tonight', 0),
  23. (9, 7, 'Madsen - Du schreibst Geschichte', 0),
  24. (10, 8, 'Bela B. feat Charlotte Roche - 1,2,3...', 0),
  25. (11, 9, 'Xavier Naidoo - Danke', 0),
  26. (12, 10, 'Placebo - Infra-red', 1),
  27. (13, 11, 'Revolverheld - Mit dir chilln', 1),
  28. (14, 12, 'Rihanna - Unfaithful', 0),
  29. (15, 13, 'Nelly Furtado - Promiscuous', 0),
  30. (16, 14, 'Robbie Williams - Rudebox', 0),
  31. (17, 15, 'Sebastian Haemer - Sommer unseres Lebens', 0),
  32. (18, 16, 'Silbermond - Meer sein', 0),
  33. (19, 17, 'Red Hot Chili Peppers - Tell me Baby', 0),
  34. (20, 18, 'Kelly Clarkson - Breakaway', 0),
  35. (21, 19, 'James Blunt - Wisemen', 2),
  36. (22, 20, 'The Pussycat Dolls - Buttons', 2);

(die tabelle)

  1. <?php
  2.  
  3.  define('****',true);
  4.  
  5.  /* General includings */
  6.  $rw_dir = '****';
  7.  include $rw_dir.'general.php';
  8.  
  9.  /* Update database */
  10.  
  11.  $sql = 'SELECT * FROM '.TABLE_LISTENERS.' ORDER BY votes DESC';
  12.     if(!$result = $db->query($sql)) {
  13.       message_error('general', 'Could not get charts statistics',__LINE__,__FILE__);
  14.     }
  15.  
  16.  while($entry = $db->fetch_row($result)) {
  17.     $entry['']

und an der stelle verzweifel ich. was tun? bitte helft mir.

danke euch im voraus,

euer a1Pha

EDIT by foxx:
  • Titel angepasst, "Noobfrage" nicht besonders informativ :)
  • Auf Anfrage von a1Pha private Informationen entfernt
This post was edited 5 times, last on 2006-11-14, 22:56 by Janek.
Edit reason: [code=sql] und [code=php] sieht doch gleich viel schöner aus xD
Avatar
llpb #2
Member since Aug 2006 · 10 posts
Group memberships: Cehmes-Entwickler, Mitglieder
Show profile · Link to this post
... Fehlerausgabe?!

PS: Im Kasten: "Stream-Info" kann man die Schriftgröße mit dem Browser verändern, wenn die etwas zu groß ist, platzt links das ganze Layout.
Avatar
Janek (Administrator) #3
User title: Admin
Member since Aug 2006 · 125 posts · Location: Potsdam
Group memberships: Administratoren, Cehmes-Entwickler, Mitglieder
Show profile · Link to this post
Hm nein es geht gan allgemein darum dieses halbe Skript fertig zu schreiben also es soll per Cron-Job täglich aufgerufen werden und die Charts neu nach den Votes sortieren.
>> PHP4You
>> Against ICQ
Avatar
llpb #4
Member since Aug 2006 · 10 posts
Group memberships: Cehmes-Entwickler, Mitglieder
Show profile · Link to this post
asooo, sry.. ich denk mal nach^^

// EDIT:
Ehm: Du fragst die Einträge nach den Votes sortiert ab (absteigend). Liest die ID und schreibst den Platz rein.

Also vorher eine
$platz_variable = 1;
dann die Schleife, die die Einträge nach den Votes sortiert abfragt;
In der Schleife: $id_des_Eintrags = Spalte 'id' lesen;
Speicher $platz_variable in die Spalte wo 'id' == $id_des_Eintrags;
++$platz_variable;

Funktioniert vielleicht sogar.
So, jetzt sind die PHP Coder hier gefragt :-D
This post was edited on 2006-08-16, 21:11 by llpb.
Avatar
Janek (Administrator) #5
User title: Admin
Member since Aug 2006 · 125 posts · Location: Potsdam
Group memberships: Administratoren, Cehmes-Entwickler, Mitglieder
Show profile · Link to this post
So sollte es funktionieren:

  1. <?php
  2.  
  3.  define('****',true);
  4.  
  5.  /* General includings */
  6.  $rw_dir = '****';
  7.  include $rw_dir.'general.php';
  8.  
  9.  /* Update database */
  10.  
  11.  $sql = 'SELECT * FROM '.TABLE_LISTENERS.' ORDER BY votes DESC';
  12.     if(!$result = $db->query($sql)) {
  13.       message_error('general', 'Could not get charts statistics',__LINE__,__FILE__);
  14.     }
  15.  
  16.  # Wenn `platz` von 0 beginnen sollte zu 0 ändern!
  17.  $i = 1;
  18.  while($entry = $db->fetch_row($result)) {
  19.     $sql_update = 'UPDATE '.TABLE_LISTENERS.' SET platz = "' . $i . '" WHERE id = "' . $entry['0'] . '"';
  20.     if(!$result_update = $db->query($sql_update)) {
  21.       message_error('general', 'Could not update charts statistics',__LINE__,__FILE__);
  22.     }
  23.     $i++;
  24.  }
  25.  
  26.  $sql_update = 'UPDATE '.TABLE_LISTENERS.' SET votes = "0"';
  27.     if(!$result_update = $db->query($sql_update)) {
  28.       message_error('general', 'Could not reset votes',__LINE__,__FILE__);
  29.     }
  30.  
  31. ?>

PS: Bitte setze dann wenn es so funktioniert noch vor den Threadtitel ein [gelöst] für die Übersicht^^

Gruß,
foxx
>> PHP4You
>> Against ICQ
This post was edited on 2006-11-14, 22:55 by Janek.
a1Pha #6
User title: wayne?
Member since Aug 2006 · 6 posts · Location: Düsseldorf / NRW / Germany
Group memberships: Mitglieder
Show profile · Link to this post
Vielen Dank, es hat wunderbar geklappt =)

Nun kanns endlich ans Coden des Profils gehen, mal schauen, was ich da für Fragen stellen muss xD

Nochmal Danke,
Euer a1Pha
Avatar
Janek (Administrator) #7
User title: Admin
Member since Aug 2006 · 125 posts · Location: Potsdam
Group memberships: Administratoren, Cehmes-Entwickler, Mitglieder
Show profile · Link to this post
Info:
Es gibt nun übrigens die neue Radio.WORX Version - zusammen mit einer neuen Domain:

http://www.radioworx.de
>> PHP4You
>> Against ICQ
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20090606-dev, © 2003-8 by Yves Goergen
Current time: 2012-02-05, 19:42:05 (UTC +01:00)