Exemplo n.º 1
0
<?php

include_once '../lib/util.php';
$db = new DBGuest();
header('Content-Type: application/json');
$res = array();
$keys = array_keys($_REQUEST);
if (count($keys) > 0) {
    $key = $keys[0];
    $value = $_REQUEST[$key];
    if ($value) {
        switch ($key) {
            case 'title':
                $res = $db->fetchAll('SELECT DISTINCT `title` FROM `summary`
				WHERE `title` LIKE ? UNION SELECT `title_english` FROM `summary`
				WHERE `title_english` LIKE ? LIMIT 30', $value . '%', $value . '%');
                break;
            case 'teacher':
                $res = $db->fetchAll('SELECT `name` FROM `staff` WHERE `name` LIKE ? LIMIT 30', $value . '%');
                break;
            case 'code':
                $res = $db->fetchAll('SELECT `code` FROM `summary` WHERE `code` LIKE ? LIMIT 30', $value . '%');
                break;
        }
    }
}
echo json_encode($res);
Exemplo n.º 2
0
<?php

include_once '../lib/util.php';
$db = new DBGuest();
if (isset($_REQUEST['department_id']) && $_REQUEST['department_id']) {
    $res = $db->fetchAll('SELECT `room_id`, `name` from `room` WHERE `department_id` = ?', $_REQUEST['department_id']);
} else {
    $res = $db->fetchAll('SELECT `room_id`, `name` from `room`');
}
header('Content-Type: application/json');
echo json_encode($res);
Exemplo n.º 3
0
}
$offset = 0;
$count = 100;
if (isset($_REQUEST['page'])) {
    $page = explode('..', $_REQUEST['page']);
    if (count($page) >= 1) {
        if (count($page) === 2 && is_numeric($page[0]) && is_numeric($page[1])) {
            $offset = (int) $page[0];
            $count = (int) $page[1] - $offset + 1;
        } else {
            if (is_numeric($page[0])) {
                $offset = (int) $page[0];
            } else {
                if (count($page) === 2 && is_numeric($page[1])) {
                }
            }
        }
    }
}
$lastquery .= ") LIMIT {$offset}, " . (min(100, $count) + 1);
$result = $db->fetchAll($lastquery);
echo '{"syllabus":[' . implode(',', array_slice($result, 0, $count)) . '],"page":' . json_encode(array('begin' => $offset, 'end' => min(100, count($result)) + $offset - 1, 'next' => count($result) > 100)) . ',"sql":"' . $lastquery . '"}';
/*
$reurn =array();
while($row=$result->fetch_assoc()){
	$return[]=json_decode($row[json]);
}

$db->close();
echo json_encode($return,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
*/
Exemplo n.º 4
0
<?php

include_once '../lib/util.php';
$db = new DBGuest();
$res = $db->fetchAll('SELECT * from `department`');
header('Content-Type: application/json');
echo json_encode($res);