Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- function showUser(str) {
- if (str == "") {
- document.getElementById("txtHint").innerHTML = "";
- return;
- } else {
- if (window.XMLHttpRequest) {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp = new XMLHttpRequest();
- } else {
- // code for IE6, IE5
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
- }
- };
- xmlhttp.open("GET","testmysql.php?q="+str,true);
- xmlhttp.send();
- }
- }
- </script>
- </head>
- </html>
- <html>
- <head>
- <script type="text/javascript" src="show.js"></script>
- <style>
- table {
- width: 100%;
- border-collapse: collapse;
- }
- table, td, th {
- border: 1px solid black;
- padding: 5px;
- }
- th {text-align: left;}
- </style>
- </head>
- <body>
- <?php
- //Sample Database Connection Script
- //Setup connection variables, such as database username
- //and password
- $hostname="localhost";
- $username="root";
- $password="";
- $dbname="grocery";
- $usertable="grocery";
- $yourfield = "NAME";
- $q = intval($_GET['q']);
- //Connect to the database
- $connection = mysqli_connect($hostname, $username, $password);
- mysqli_select_db($connection, $dbname);
- $query="SELECT * FROM user WHERE id = '".$q."'";
- $result = mysqli_query($connection,$query);
- echo "<table>
- <tr>
- <th>Name</th>
- <th>Price</th>
- <th>Amount</th>
- </tr>";
- if($result){
- while($row = mysqli_fetch_array($result)) {
- echo "<tr>";
- echo "<td>" . $row['NAME'] . "</td>";
- echo "<td>" . $row['PRICE'] . "</td>";
- echo "<td>" . $row['AMOUNT'] . "</td>";
- echo "</tr>";
- }
- }
- echo "</table>";
- mysqli_close($connection);
- /*
- //Setup our query
- //$query = "SELECT * FROM $usertable";
- Run the Query
- $result = mysqli_query($connection,$query);
- //If the query returned results, loop through
- // each result
- if($result)
- {
- while($row = mysqli_fetch_array($result))
- {
- $name = $row["$yourfield"];
- echo "Name: " . $name;
- }
- }
- */
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement