Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projekt/ajax/
ajax_service.php
createtable.php
dbconnection.php
deletetable.php
main.js
main.php
ajax_service.php
35 lines UTF-8 Windows (CRLF)
<?php
include("dbconnection.php");
// Rensa output buffer från dbconnection
ob_clean();
if (isset($_GET["name"])) {
$key = $_GET["name"];
if (!empty($key)) {
// T.ex. "LIKE 'h%'" hittar alla namn som börjar på h/H
$query = "SELECT * FROM ajax WHERE firstname LIKE ? ORDER by firstname";
$stmt = $dbconn->prepare($query);
$data = array($key."%");
$stmt->execute($data);
$output = "";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$name = $res["firstname"];
if ($output != "") {
// Så länge som det inte är första värdet, lägg till kommatecknet
$output .= ", ";
}
$output .= $name;
}
} else {
$output = "";
}
}
echo $output;
?>