Handles when contact_id exceeds greatest or least contact_id.

* will go to the closest contact_id, nice behavior.
This commit is contained in:
Jonathan Rosenbaum
2017-10-31 07:03:00 +00:00
parent b63df15721
commit bc3c7450fd
2 changed files with 33 additions and 1 deletions
+10
View File
@@ -14,6 +14,14 @@ $handler = PhpConsole\Handler::getInstance();
$handler->start();
*/
// Return total contacts
if (isset($_POST['total'])) {
$query = "SELECT COUNT(contact_id) AS total FROM contacts;";
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
echo json_encode($result);
}
// Return name
if (isset($_POST['name'])) {
$query = "SELECT CONCAT(contacts.first_name, ' ', contacts.middle_initial, ' ',contacts.last_name) AS full_name
@@ -63,9 +71,11 @@ $handler->start();
$sql = mysql_query($query, $YBDB) or die(mysql_error());
while ( $result = mysql_fetch_assoc($sql) ) {
$results[] = $result;
}
echo json_encode($results);