Example #1
0
<?php

/**
 * Created by PhpStorm.
 * User: Yu
 * Date: 2015/4/9
 * Time: 23:44
 */
require_once "rank_api.php";
echo "DELETE FROM rank;\r\nINSERT INTO rank(id, pre_wealth, cur_wealth, name)\r\n     SELECT users.id, users.pre_wealth, users.cur_wealth, users.name FROM users\r\n     ORDER BY users.cur_wealth DESC LIMIT 0, 5;\r\nUPDATE rank SET ratio = (rank.cur_wealth - rank.pre_wealth)/rank.pre_wealth WHERE 1;\r\n\r\nDELETE FROM rank_ratio;\r\nINSERT INTO rank_ratio(id, name, ratio, cur_wealth)\r\n     SELECT users.id, users.name, (users.cur_wealth - users.pre_wealth) / users.pre_wealth AS GRADE, users.cur_wealth FROM users\r\n          ORDER BY GRADE DESC LIMIT 0, 5;\r\n";
load_rank_lists(dbConnect());
Example #2
0
}
function need_refresh($conn)
{
    $res = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM status"));
    date_default_timezone_set('PRC');
    if (time() - strtotime($res['last_refresh']) > 60) {
        //echo "test:".(time() - strtotime($res['last_refresh']));
        return 1;
    } else {
        return 0;
    }
}
$connection = dbConnect();
if (need_refresh($connection) == 1) {
    load_market($connection);
    load_rank_lists($connection);
    set_last_refresh($connection);
} else {
}
//SHOULD JUMP TO HOME PAGE HERE
//TODO
$res = mysqli_query($connection, "SELECT name, price, goods_id FROM " . MARKET_TABLE . " WHERE place_id = 3");
$n = mysqli_num_rows($res);
$arr = array();
for ($i = 0; $i < $n; $i++) {
    $row = mysqli_fetch_array($res);
    $name = $row['name'];
    $price = $row['price'];
    $goods_id = $row['goods_id'];
    $a = array('name' => $name, 'price' => $price, 'goods_id' => $goods_id);
    array_push($arr, $a);