Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- sql::on();
- if ($_GET['type']=="depart") {
- sql::query('
- DELETE FROM `course`
- WHERE
- `pseudo` = \''.sql::escape($_GET['pseudo']).'\'
- AND arriver = \'0000-00-00 00:00:00\'
- ');
- sql::query('
- INSERT INTO `course` ( pseudo ) VALUES (\''.sql::escape($_GET['pseudo']).'\' )
- ');
- } elseif ($_GET['type']=="arriver") {
- sql::query('
- UPDATE `course`
- SET `arriver` = NOW()
- WHERE `pseudo` = \''.sql::escape($_GET['pseudo']).'\' AND arriver = \'0000-00-00 00:00:00\'
- ');
- sql::query('
- UPDATE `course`
- SET `score` = TIMEDIFF(arriver,depart)
- WHERE `pseudo` = \''.sql::escape($_GET['pseudo']).'\' AND `score`= 0
- ');
- }
- class LuaSerialize
- {
- private static function is_assoc($array)
- {
- return (bool)count(array_filter(array_keys($array), 'is_string')) && array_keys($array) !== range(0, count($array) - 1);
- }
- function serialize($value)
- {
- if (is_object($value)) {
- $value = (array)$value;
- }
- if (is_array($value)) {
- $members = array();
- if (self::is_assoc($value)) {
- foreach ($value as $k => $v) {
- $members[] = '[' . $this->serialize($k) .']=' . $this->serialize($v);
- }
- } else {
- foreach ($value as $k => $v) {
- $members[] = $this->serialize($v);
- }
- }
- return '{'.implode(',', $members).'}';
- } elseif (is_bool($value)) {
- return $value ? 'true' : 'false';
- } elseif (is_string($value)) {
- return var_export($value, true);
- } elseif (is_numeric($value)) {
- return $value;
- } elseif ($value === null) {
- return 'nil';
- }
- throw new \Exception('Unknown type to serialize: ' . $value);
- }
- }
- $lua=new LuaSerialize();
- $data=array('record'=>array(),'dernier'=>array());
- $req=sql::query('
- SELECT c.pseudo, MIN(c.score) AS scoreMin
- FROM course c
- WHERE c.score != 0
- GROUP BY c.pseudo
- ORDER BY scoreMin
- LIMIT 10
- ');
- while($d=$req->fetch_object()) {
- $data['record'][]=$d;
- }
- $req=sql::query('
- SELECT `pseudo`, score
- FROM `course`
- WHERE score != 0
- ORDER BY `arriver` DESC
- LIMIT 5
- ');
- while($d=$req->fetch_object()) {
- $data['dernier'][]=$d;
- }
- sql::off();
- echo $lua->serialize($data);
Add Comment
Please, Sign In to add comment