mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-02-22 08:53:23 -05:00
Handles when contact_id exceeds greatest or least contact_id.
* will go to the closest contact_id, nice behavior.
This commit is contained in:
parent
b63df15721
commit
bc3c7450fd
@ -5,11 +5,33 @@ $(function(){
|
||||
$.ajaxSetup({async:false});
|
||||
|
||||
var contact_id = $("#contact_id").text();
|
||||
|
||||
|
||||
if (contact_id) {
|
||||
|
||||
$("table").attr("width","");
|
||||
|
||||
// handle logic for previous and next buttons
|
||||
//var prev, next;
|
||||
|
||||
var prev = Number(contact_id) - 1, next = Number(contact_id) + 1;
|
||||
if (prev <= 0) {
|
||||
prev = 1;
|
||||
}
|
||||
if (next === 0) {
|
||||
next = 1;
|
||||
}
|
||||
|
||||
$.post("json/reports.php", { total: 1 }, function (data) {
|
||||
var obj = $.parseJSON(data);
|
||||
|
||||
if (contact_id > obj.total) {
|
||||
prev = obj.total;
|
||||
next = obj.total;
|
||||
} else if (contact_id === obj.total) {
|
||||
next = obj.total;
|
||||
}
|
||||
});
|
||||
|
||||
$(".stats-left").attr("href","/individual_history_log.php?contact_id=" + prev);
|
||||
$(".stats-right").attr("href","/individual_history_log.php?contact_id=" + next);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user