Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MySQL][HTML] Sortowanie tabeli
Amakesh
post 14.03.2016, 10:39:47
Post #1





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 26.06.2014

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


Witam! Mam taki kod jak poniżej. Generuje on tabelę html i wyświetla w niej konkretne rekordy z bazy danych. Jednak gdy chcę te tabelę posortować np po nazwie użytkownika, posortowane rekordy zostają do tej tabeli dopisane zamiast zastapić poprzednie. Jak to naprawić?

  1. <table name="table" border="1" style="color:1c4e93;">
  2. <thead>
  3.  
  4. <tr><!--<form method = "post" >-->
  5. <th class = "th"><input type="hidden" name="id" value="id" /><input type="submit" value="ID" name="id_user" class="btn btn-default btn-success"></th>
  6. <th class = "th"><input type="hidden" name="username" value="username" /><input type="button" value="Login" name="uname" class="btn btn-default btn-success" style="width: 222px;" onClick="location.href='https://www.solaris-ustronie.eu/joomla/administrator/modules/mod_activate/users_sort.php?param=username'"></th>
  7. <th class = "th"><input type="hidden" name="password" value="password" /><input type="submit" value="Hasło" name="upass" class="btn btn-default btn-success" style="width: 222px;"></th>
  8. <th class = "th"><input type="hidden" name="lname" value="lname" /><input type="submit" value="Nazwisko" name="ulname" class="btn btn-default btn-success" style="width: 222px;"></th>
  9. <th class = "th"><input type="hidden" name="surname" value="surname" /><input type="submit" value="Imię" name="ufname" class="btn btn-default btn-success" style="width: 222px;"></th>
  10. <th class = "th"><input type="hidden" name="email" value="email" /><input type="submit" value="Email" name="umail" class="btn btn-default btn-success" style="width: 222px;"></th>
  11. <th class = "th" width="120px;"><div style = "width: 120px;">Opcje</div></th>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr>
  16.  
  17. <?php
  18.  
  19. function show($query_disp){
  20.  
  21. include ('/var/www/vhosts/solaris-ustronie.eu/httpdocs/joomla/administrator/modules/mod_activate/db_joomla.php');
  22.  
  23.  
  24. $resultSet = mysql_query($query_disp, $con);
  25. $table ="jos_users";
  26. $id_col="id";
  27.  
  28.  
  29.  
  30. //ini_set('max_execution_time', 300);
  31.  
  32. while($row = mysql_fetch_array($resultSet)) {
  33.  
  34. $id= $row['id'];
  35. $name= $row['username'];
  36. $pass=$row['password'];
  37. $llname =$row['name'];
  38. $ffname=$row['surname'];
  39. $mail = $row['email'];
  40.  
  41.  
  42. ?>
  43.  
  44.  
  45. <form id="form_users" action = "https://www.solaris-ustronie.eu/joomla/administrator/modules/mod_activate/edit_user.php" method = "GET"><p>
  46. <td class="container" width = "40px;"><center><?php echo $row['id'];?></td>
  47. <td class="container" ><div><input type="text" name="name" size="40;" line-height="0px" value="<?php echo $row['username'];?>"></input></div></td>
  48. <td class="container"><div class="td_div"><input type="text" name="pass" size="40" line-height="0px" value="<?php echo $row['password'];?>"></input></div></td>
  49. <td class="container"><div><input type="text" name="llname" size="40" line-height="0px" value="<?php echo $row['name'];?>"></input></div></td>
  50. <td class="container"><div><input type="text" name="ffname" size="40" line-height="0px" value="<?php echo $row['surname'];?>"></input></div></td>
  51. <td class="container"><div><input type="text" name="mail" size="40" line-height="0px" value="<?php echo $row['email'];?>"></input></div></td>
  52.  
  53. <td class="container">
  54. <div> <input type="hidden" name="id" value="<?php echo $id; ?> " /><div>
  55. <div><input type="hidden" name="table" value="<?php echo $table; ?> " /></div>
  56. <div><div class="opt_btn" ><input type="submit" value="Zapisz" class="btn btn-default btn-success"></div></form></p><div class="opt_btnu"> <input type="button" value="Usuń" class="btn btn-primary" style="width: 58px;" onClick="location.href='https://www.solaris-ustronie.eu/joomla/administrator/modules/mod_activate/delete.php?param=<?php echo $table;?>,<?php echo $id_col;?>,<?php echo $id;?>'"></div></div>
  57. </td>
  58. </tr>
  59.  
  60. <?php } mysql_close();}
  61.  
  62. show($query_disp);
  63. if(isset ($_GET['query']))
  64.  
  65. {
  66.  
  67. $query=$_GET['query'];
  68.  
  69. $query0="SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent'";
  70. $query1 = "SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent' ORDER BY id ASC";
  71. $query2 = "SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent' ORDER BY username ASC";
  72. $query3 = "SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent' ORDER BY name ASC";
  73. $query4 = "SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent' ORDER BY surname ASC ";
  74. $query5 = "SELECT * FROM jos_users WHERE program_user = '1' AND parent = '$parent' ORDER BY email ASC ";
  75.  
  76.  
  77. if($query=='query1' )
  78. {
  79. $query_disp=$query1;
  80. }
  81. if($query=='query2'){
  82.  
  83. $query_disp=$query2;
  84.  
  85. parent.window.location.reload();
  86. show($query_disp);
  87. }
  88. if($query=='query3'){
  89.  
  90. $query_disp=$query3;
  91. }
  92. if($query=='query4'){
  93.  
  94. $query_disp=$query4;
  95. }
  96. if($query=='query5'){
  97.  
  98. $query_disp=$query5;
  99. }
  100.  
  101. else
  102. {
  103. $query_disp=$query0;
  104.  
  105. }
  106. $error= $query_disp;
  107.  
  108.  
  109.  
  110. } ?>
  111. </tbody>
  112. </table>
Go to the top of the page
+Quote Post
rad11
post 14.03.2016, 10:48:10
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


Hmmm dziwne w tym kodzie co podałeś nigdzie nie widzę aby miało coś dodawać, albo jestem ślepy.
Go to the top of the page
+Quote Post
Amakesh
post 14.03.2016, 11:32:39
Post #3





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 26.06.2014

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


Cytat(rad11 @ 14.03.2016, 10:48:10 ) *
Hmmm dziwne w tym kodzie co podałeś nigdzie nie widzę aby miało coś dodawać, albo jestem ślepy.

Widok przed użyciem sortowania


Widok po użyciu sortowania(kliknięcie nagłówka wybranej kolumny).
Go to the top of the page
+Quote Post
rad11
post 14.03.2016, 11:37:03
Post #4





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


a users_sort.php jak wygląda?
Go to the top of the page
+Quote Post
Amakesh
post 14.03.2016, 11:40:25
Post #5





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 26.06.2014

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


  1. <?php
  2.  
  3. $param=$_GET['param'];
  4. $param1 = "id";
  5. $param2 = "username";
  6. $param3 = "name";
  7. $param4 = "surname";
  8. $param4 = "email";
  9.  
  10.  
  11. if($param==$param1){
  12.  
  13. header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query1');
  14. }
  15. if($param==$param2){
  16.  
  17. header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query2');
  18. }
  19. if($param==$param3){
  20.  
  21. header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query3');
  22. }
  23. if($param==$param4){
  24.  
  25. header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query4');
  26. }
  27. if($param==$param5){
  28.  
  29. header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query5');
  30. }
  31.  
  32. else{
  33.  
  34. // header('Location:https:// / /index.php?option=com_content&view=article&id=6&Itemid=165&query=query0');
  35.  
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ?>


Ten post edytował Amakesh 14.03.2016, 11:46:38
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: 1.08.2025 - 02:28