Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <script language="javascript" type="text/javascript">
- function showCustomer(str){
- var choice = str.value;
- var xmlhttp;
- if (choice==0){
- document.getElementById("display").innerHTML="No person selected";
- return;
- }
- if(window.XMLHttpRequest){
- xmlhttp=new XMLHttpRequest();
- }else{
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function();{
- if(xmlhttp.readyState==4 && xmlhttp.status==200){
- document.getElementById("display").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","showtable.php?q="+str,true);
- xmlhttp.send();
- }
- </script>
- <p>
- <form>
- <select name="customer" onchange="showCustomer(this)">
- <?php
- $hostname = 'localhost';
- $username = 'root';
- $password = '';
- try {
- $dbh = new PDO("mysql:host=$hostname;dbname=lab9",$username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
- $dbh->exec("SET CHARACTER SET UTF8");
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- $stmt=$dbh->prepare("SELECT id,name FROM customers");
- //echo "<p>";
- //echo "<select name="customer" onchange="".<script>showCustomer(this.value)</script>;."">";
- $zero=0;
- echo "<option value=".$zero.">Select person</option>";
- $stmt->execute();
- $result=$stmt->fetchAll();
- foreach ($result as $row)
- {
- //unset($id, $name);
- $id = $row['id'];
- $name = $row['name'];
- echo "<option value=".$id.">".$name."</option>";
- }
- ?>
- </select>
- </form>
- </p>
- <p id="display"></p>
- </body>
- </html>
- <?php
- $q=$_GET["q"];
- $hostname = 'localhost';
- $username = 'root';
- $password = '';
- try {
- $dbh = new PDO("mysql:host=$hostname;dbname=lab9",$username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
- $dbh->exec("SET CHARACTER SET UTF8");
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- $stmt=$dbh->prepare("SELECT id,name,adress,city,tk,phone,mobile FROM customers WHERE id=".$q."");
- $stmt->execute();
- $result=$stmt->fetchAll();
- foreach($result as $row){
- echo "<p>";
- echo "<table border='1'>";
- echo "<tr>";
- echo "<td>ID</td><td>".$row['id']."</td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Name</td><td>".$row['name']."</td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Adress</td><td>".$row['adress']."</td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Town</td><td>".$row['city']."</td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Τ.Κ.</td><td>".$row['tk']."</td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Telephone number</td>".$row['phone']."<td></td>";
- echo "</tr>";
- echo "<tr>";
- echo "<td>Mobile</td><td>".$row['mobile']."</td>";
- echo "</tr>";
- echo "</table>";
- echo "</p>";
- }
- ?>
Add Comment
Please, Sign In to add comment