Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Rekordy alfabetycznie
-Abees-
post
Post #1





Goście







Witam mam przykładowy skrypt wyświetlający liste banów z bazy danych:
  1. <?php
  2. function connect_db(){
  3. mysql_connect('server', 'username', 'password');
  4. mysql_select_db(database) or die( "Unable to select database");
  5. }
  6. connect_db();
  7.  
  8. $sql = 'SELECT * FROM `bans`'; // This is the query to be made
  9. $query = mysql_query($sql); // Here we execute the query
  10. ?>
  11. <h2>Banlist</h2>
  12. <br>
  13. <table border=1>
  14. <tr>
  15. <td><b>Name</b></td>
  16. <td><b>Release date</b></td>
  17. <td><b>Reason</b></td>
  18. </tr>
  19. <?php
  20. while ($player = mysql_fetch_array($query)) // Here we run thru the query's array
  21. {
  22. if ($player['type'] == 2) // We print only the Player Bans
  23. {
  24. echo '<tr>';
  25. echo '<td>'.$player['player'].'</td>'; // Players name...
  26. echo '<td>'.date('M d Y, H:i:s',$player['time']).'</td>'; // Release date...
  27. echo '<td>'.$player['reason'].'</td>'; // And reason!
  28. echo '</tr>'; // Done! :)
  29. }
  30. }
  31. ?>
  32. </table>

Chciałbym by po wciśnięciu np napisu Name wyświetliły się rekordy od A do Z a po 2 kliku od Z do A da się tak?
Jak tak to czy ktoś mógł w ten skrypt to w robić i powiedzieć jak to zrobił (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
Dziękuje.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
piotrooo89
post
Post #2


Newsman


Grupa: Moderatorzy
Postów: 4 005
Pomógł: 548
Dołączył: 7.04.2008
Skąd: Trzebinia/Kraków




to problem z js bardziej niż z mysql'a.

  1. <table border=1 id="s">
  2. <tr>
  3. <td class="sort"><b>Name</b></td>
  4. <td class="sort"><b>Release date</b></td>
  5. <td class="sort"><b>Reason</b></td>
  6. </tr>
  7. <?php
  8. while ($player = mysql_fetch_array($query)) // Here we run thru the query's array
  9. {
  10. if ($player['type'] == 2) // We print only the Player Bans
  11. {
  12. echo '<tr>';
  13. echo '<td>'.$player['player'].'</td>'; // Players name...
  14. echo '<td>'.date('M d Y, H:i:s',$player['time']).'</td>'; // Release date...
  15. echo '<td>'.$player['reason'].'</td>'; // And reason!
  16. echo '</tr>'; // Done! :)
  17. }
  18. }
  19. ?>
  20. </table>

i skrypt:
  1. <?php
  2. onl=(window.onload||new Function); 
  3. onload=function()
  4. { 
  5. onl(); 
  6. for(var i=0,d; d=document.getElementsByTagName('tr')[i++];)
  7. { 
  8. for(var j=0,e; e=d.getElementsByTagName('td')[j];j++)
  9. {
  10. if(e.className=='sort')
  11. { 
  12. e.n=j; e.onclick=function()
  13. {
  14. sort(this.n,this);
  15. }  
  16. } 
  17. } 
  18. }  
  19. } 
  20. function sort(v,d)
  21. { 
  22. d.o>0?(d.o=-1):(d.o=1); 
  23. var t=d.parentNode.parentNode.parentNode.getElementsByTagName('tbody')[0]; 
  24. var c=[]; 
  25. for(var i=0,w;w=t.getElementsByTagName('tr')[i];i++)
  26. { 
  27. c[i]=[]; 
  28. for(var j=0;k=w.getElementsByTagName('td')[j];j++)
  29. { 
  30. c[i][j]=k.firstChild.data; 
  31. } 
  32. } 
  33. c.sort(function(a,b){return a[v]>b[v]?d.o:-d.o}); 
  34. for(var i=0,w;w=t.getElementsByTagName('tr')[i];i++)
  35. { 
  36. for(var j=0;k=w.getElementsByTagName('td')[j];)
  37. { 
  38. k.firstChild.data=c[i][j++]; 
  39. } 
  40. } 
  41. }
  42. ?>


ja z czegoś takiego korzystam.

Ten post edytował piotrooo89 24.05.2008, 17:23:26
Go to the top of the page
+Quote Post

Posty w temacie
- Abees   [PHP][MYSQL]Rekordy alfabetycznie   24.05.2008, 17:03:41
- - piotrooo89   to problem z js bardziej niż z mysql'a. ...   24.05.2008, 17:23:12
- - Abees   No thx a wytłumaczysz bardziej skrypt itp?   24.05.2008, 17:27:31
- - Abees   ODŚWIEŻAM! Proszę o pomoc!   24.05.2008, 19:26:00
- - Abees   A może: SELECT * FROM nazwa_tabeli ORDER BY nazwa_...   25.05.2008, 08:57:18
- - Gośc   [PHP] pobierz, plaintext <?php if(...   25.05.2008, 09:01:58


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 Aktualny czas: 3.10.2025 - 17:29