Guest User

Untitled

a guest
May 16th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. </head>
  7. <body>
  8.  
  9.  
  10. <script language="javascript" type="text/javascript">
  11. function showCustomer(str){
  12. var choice = str.value;
  13.  
  14. var xmlhttp;
  15. if (choice==0){
  16. document.getElementById("display").innerHTML="No person selected";
  17. return;
  18. }
  19. if(window.XMLHttpRequest){
  20. xmlhttp=new XMLHttpRequest();
  21. }else{
  22. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  23. }
  24. xmlhttp.onreadystatechange=function();{
  25. if(xmlhttp.readyState==4 && xmlhttp.status==200){
  26. document.getElementById("display").innerHTML=xmlhttp.responseText;
  27. }
  28. }
  29. xmlhttp.open("GET","showtable.php?q="+str,true);
  30. xmlhttp.send();
  31. }
  32. </script>
  33.  
  34.  
  35. <p>
  36. <form>
  37. <select name="customer" onchange="showCustomer(this)">
  38. <?php
  39. $hostname = 'localhost';
  40. $username = 'root';
  41. $password = '';
  42. try {
  43. $dbh = new PDO("mysql:host=$hostname;dbname=lab9",$username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
  44. $dbh->exec("SET CHARACTER SET UTF8");
  45. }
  46. catch(PDOException $e)
  47. {
  48. echo $e->getMessage();
  49. }
  50. $stmt=$dbh->prepare("SELECT id,name FROM customers");
  51. //echo "<p>";
  52. //echo "<select name="customer" onchange="".<script>showCustomer(this.value)</script>;."">";
  53. $zero=0;
  54. echo "<option value=".$zero.">Select person</option>";
  55. $stmt->execute();
  56. $result=$stmt->fetchAll();
  57. foreach ($result as $row)
  58. {
  59. //unset($id, $name);
  60. $id = $row['id'];
  61. $name = $row['name'];
  62. echo "<option value=".$id.">".$name."</option>";
  63. }
  64. ?>
  65. </select>
  66. </form>
  67. </p>
  68.  
  69.  
  70. <p id="display"></p>
  71. </body>
  72. </html>
  73.  
  74. <?php
  75. $q=$_GET["q"];
  76.  
  77. $hostname = 'localhost';
  78. $username = 'root';
  79. $password = '';
  80. try {
  81. $dbh = new PDO("mysql:host=$hostname;dbname=lab9",$username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
  82. $dbh->exec("SET CHARACTER SET UTF8");
  83. }
  84. catch(PDOException $e)
  85. {
  86. echo $e->getMessage();
  87. }
  88. $stmt=$dbh->prepare("SELECT id,name,adress,city,tk,phone,mobile FROM customers WHERE id=".$q."");
  89. $stmt->execute();
  90. $result=$stmt->fetchAll();
  91. foreach($result as $row){
  92. echo "<p>";
  93. echo "<table border='1'>";
  94. echo "<tr>";
  95. echo "<td>ID</td><td>".$row['id']."</td>";
  96. echo "</tr>";
  97. echo "<tr>";
  98. echo "<td>Name</td><td>".$row['name']."</td>";
  99. echo "</tr>";
  100. echo "<tr>";
  101. echo "<td>Adress</td><td>".$row['adress']."</td>";
  102. echo "</tr>";
  103. echo "<tr>";
  104. echo "<td>Town</td><td>".$row['city']."</td>";
  105. echo "</tr>";
  106. echo "<tr>";
  107. echo "<td>Τ.Κ.</td><td>".$row['tk']."</td>";
  108. echo "</tr>";
  109. echo "<tr>";
  110. echo "<td>Telephone number</td>".$row['phone']."<td></td>";
  111. echo "</tr>";
  112. echo "<tr>";
  113. echo "<td>Mobile</td><td>".$row['mobile']."</td>";
  114. echo "</tr>";
  115. echo "</table>";
  116. echo "</p>";
  117. }
  118.  
  119.  
  120. ?>
Add Comment
Please, Sign In to add comment