Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] [MySQL] wyświetlenie wyników + sortowanie
-tobiaszf-
post
Post #1





Goście







Jak wyświetlić wyniki z bazy, żeby były widoczne również nagłówki, tak żeby potem po nagłówkach można było sortować na stronie (tzn. jak klikam na hiperłącze w nagłówku to cała tabela jest sortowana właśnie po tym nagłówku)


strona gdzie jest skrypt

  1. <?php
  2.  
  3. $connection = @mysql_connect('formularz.fo.funpicsql.de', '***', '****')
  4. or die('error');
  5. $db = @mysql_select_db('****', $connection)
  6. or die('error');
  7.  
  8.  
  9.  
  10. $result = mysql_query("SELECT * FROM test ORDER BY distance")
  11. or die('error');
  12.  
  13.  
  14.  
  15. header('Content-type: text/html; charset=utf-8');
  16. if(mysql_num_rows($result) > 0) {
  17.  
  18. echo "<table cellpadding=\"1\" border=1>";
  19. while($r = mysql_fetch_assoc($result)) {
  20. echo "<tr>";
  21. echo "<TR>";
  22. echo "</TR>";
  23. echo "<td>".$r['name']."</td>";
  24. echo "<td>".$r['surrname']."</td>";
  25. echo "<td>".$r['distance']."</td>";
  26.  
  27. echo "<td>
  28. <a href=\"results.php?a=del&amp;id={$r['id']}\">DEL</a>
  29. <a href=\"results.php?a=edit&amp;id={$r['id']}\">ADD room</a>
  30. </td>";
  31. echo "</tr>";
  32. }
  33. echo "</table>";
  34. }
  35. $a = trim($_GET['a']);
  36. $id = trim($_GET['id']);
  37.  
  38. if($a == 'del' and !empty($id)) {
  39.  
  40.  
  41. mysql_query("DELETE FROM test WHERE id='$id'")
  42. or die('error '.mysql_error());
  43.  
  44. echo 'ok';
  45. }
  46.  
  47. $a = trim($_REQUEST['a']);
  48. $id = trim($_GET['id']);
  49.  
  50. if($a == 'edit' and !empty($id)) {
  51.  
  52. $result = mysql_query("SELECT * FROM test WHERE
  53. id='$id'")
  54. or die('error');
  55.  
  56. if(mysql_num_rows($result) > 0) {
  57.  
  58. $r = mysql_fetch_assoc($result);
  59.  
  60. echo '<form action="results.php" method="post">
  61. <input type="hidden" name="a" value="save" />
  62. <input type="hidden" name="id" value="'.$id.'" />
  63. room:<br />
  64. <input type="text" name="room"
  65. value="'.$r['room'].'" /><br />
  66. <input type="submit" value="save" />
  67. </form>';
  68. }
  69. }
  70. elseif($a == 'save') {
  71.  
  72. $id = $_POST['id'];
  73. $room = trim($_POST['room']);
  74.  
  75. mysql_query("UPDATE test SET room='$room',
  76. room='$room' WHERE id='$id'")
  77. or die('error');
  78. echo 'ok';
  79. }
  80.  
  81.  
  82. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 20.08.2025 - 11:27