<?php

if (isset($_GET["user"])) {
    $toMatch = $_GET["user"];
} else {
    die("I feel so alone.");
}

//connect to the database
$dbconn = pg_Connect("host=capstone06.cs.pdx.edu dbname=real user=postgres password=bees");
if (!$dbconn) {
    die("Error connecting to database.");
}


$result = pg_exec($dbconn, "SELECT username FROM users;");
$num = pg_numrows($result);

for ($i = 0; $i < $num; $i++) {
    $array = pg_fetch_array($result, $i);
    if(strpos($array[0], $toMatch)) {
        $names[] = $array[0];
    }
    if(sizeof($names) > 4) {
        break;
    }
}

echo('{"names": ');
echo(json_encode($names));
echo('}');


pg_close($dbconn);

<?php

//connect to the database
$dbconn = pg_Connect("host=capstone06.cs.pdx.edu dbname=real user=postgres password=bees");
if (!$dbconn) {
    die("Error connecting to database.");
}

echo('{"users":[');

$result = pg_exec($dbconn, "SELECT username FROM users;");
$num = pg_numrows($result);

for ($i = 0; $i < $num; $i++) {
    $array = pg_fetch_array($result, $i);
    if ($i > 0) {
	echo(', ');
    }
    echo('{"username": "' . $array[0] . '"}');
}

echo('] }');

pg_close($dbconn);

Revert "Added a required GET parameter and changed the output format. It now only returns up to 5 names."
Revert "Added a required GET parameter and changed the output format.  It now only returns up to 5 names."

This reverts commit f7343f7f18e0eaead9c3bc0106d7731509885641.
