Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. function connection($serwer,$login,$pass,$db)
  4. {
  5. $conn=mysql_connect($serwer,$login,$pass,$db)
  6. or die("Blad poloczenia:".mysql_error());
  7. mysql_select_db($db);
  8. return $conn;
  9. }
  10. connection("localhost","16_widlak","U3s5r2k4e9","16_widlak");
  11.  
  12. //część 1 - wyświetl tylko nazwy wszystkich tabel w swojej bazie `XX_nazwisko`
  13.  
  14. function Bolt($query){
  15. $result=mysql_query($query) or die("Bład w zapytaniu $query: " . mysql_error());
  16. return $result;
  17. }
  18.  
  19.  
  20. $table=$_GET['table'];
  21. $showtables="SELECT * FROM ".$_GET['table'];
  22. $sort=$_POST['sort'];
  23.  
  24. if (!isset($_GET['table']) || empty($_GET['table'])){
  25. $query="SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '16_kwiek'";
  26. $result = mysql_query ($query);
  27. while($row = mysql_fetch_array($result, MYSQL_NUM)) {
  28. echo "<a href=\"?table=".$row[0]."\">";
  29. foreach ($row as $elem) echo " $elem ";
  30. echo "</a>";
  31. echo "<br>";
  32. }
  33. }
  34. else {
  35. echo "<form method='get'> <input type='submit' value='--- BACK ---'> </form>";
  36.  
  37. //część 4 - informacja kiedy tabela była ostatnio modyfikowana i ile dni temu została stworzona
  38.  
  39. $query="SELECT UPDATE_TIME from information_schema.TABLES WHERE TABLE_NAME='$table' AND TABLE_SCHEMA='16_kwiek'";
  40. $result= Bolt($query);
  41. $row = mysql_fetch_array($result, MYSQL_NUM);
  42. echo "The table's last update was on: " .$row[0];
  43. echo "<br>";
  44.  
  45. $query="SELECT current_date()-date(UPDATE_TIME) FROM information_schema.TABLES WHERE TABLE_NAME='".$table ."' AND TABLE_SCHEMA='16_kwiek'";
  46. $result= Bolt($query);
  47. $row = mysql_fetch_array($result, MYSQL_NUM);
  48. echo "The table was created: " .$row[0]. " days ago.";
  49. echo "<br>";
  50.  
  51. }
  52.  
  53. $sort=$_POST['sort'];
  54. $table=$_GET['table'];
  55.  
  56.  
  57. echo "<br><br><table ><tr>";
  58.  
  59. //część 2 - wyświetlenie zawartości tabeli + część 3 - posortowanie tabeli
  60.  
  61. if (empty ($_POST['sort'])){
  62. $query="SELECT * FROM $table";
  63. echo "$table";
  64. }
  65. else {
  66. $query="SELECT * FROM $table ORDER BY $sort;";
  67. echo "$table is sorted by $sort";
  68. }
  69.  
  70. echo "</th></tr><br><tr><br>";
  71. $result = Bolt($query);
  72.  
  73. while($column=mysql_fetch_field($result)){
  74. echo "<th><form action='' method='post'>";
  75. echo "<input type='hidden' value='".$column->name."' name='sort'><input type='submit' value='".$column->name."'>";
  76. echo "</form></th>";
  77. }
  78.  
  79. echo "</tr><br>";
  80.  
  81. while($row = mysql_fetch_array($result, MYSQL_NUM)) {
  82. foreach ($row as $elem) echo "<td>$elem</td>";
  83. echo "</tr>";
  84. }
  85. echo "</table>";
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement