Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/ajax/

get_matching_names.php
index.php
ovn_1 copy.php
ovn_1.php

get_matching_names.php

25 lines UTF-8 Windows (CRLF)
<?php
include("../databaser/dbconnection.php");
$text = $_GET["part"];

try {
    
$sql = "SELECT * FROM ajax_ovn_1 WHERE name LIKE ? ORDER BY name";
    
$stmt = $dbconn->prepare($sql);
    
$data = [$text . "%"];
    
$stmt->execute($data);

    
$output = "";

    while (
$person = $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$print = $person["name"] . ": " . $person["score"] . " Poäng";
        if (
$output == "") {
            
$output = $print;
        } else {
            
$output .= ", " . $print;
        }
    }
    echo (
$output);
} catch (
PDOException $e) {
    echo (
$e->getMessage());
}