讀古今文學網 > 微信公眾平台開發:從零基礎到ThinkPHP5高性能框架實踐 > 24.5.7 中獎記錄查詢 >

24.5.7 中獎記錄查詢

對於中獎的用戶,還需要提供中獎記錄查詢功能,以便他們方便兌獎。中獎記錄查詢很簡單,直接在抽獎記錄表中檢索數據即可。其實現代碼如下。


function getLotteryItem($openid)
{
    include_once('mysql.class.php');
    $db = new class_mysql;
    $mysql_state = "SELECT * FROM  'wx_winner' WHERE LENGTH('award') > 0 AND 'openid' 
    = '$openid'";
    $result = $db->query_array($mysql_state);
    // var_dump($result);
    if (count($result) == 0){
        return '
            <tr>
                <td>你還沒有中過獎</td>
            </tr>
        ';
    }else{
        $content = "";
        foreach ($result as $index => $item){
            $title = "獎品:".$item["award"]."<br>時間:".$item["getdate"]."<br>狀態:
            ".(($item["status"] == 0)?"未領取":"已領取");
            $content .= '
                <tr>
                    <td>'.$title.'</td>
                </tr>
            ';
        }
        return $content;
    }
}