doulidai6316 2013-07-07 03:20
浏览 32
已采纳

Php准备方法我应该在哪里使用While循环

I am new to PHP prepare method, I need some help to use while loop in the following code.

Here is the query function

function query($query, $bindings, $conn) {
    $stmt = $conn->prepare($query);
    $stmt-> execute($bindings);
    $result = $stmt->fetchAll();

    return $result ? $result : false;
}

and the query

$home_team = query('SELECT home_team FROM premier_league
                    WHERE match_date >= :current_date
                    AND pre_selected = :pre_selected
                    ORDER BY match_date LIMIT 5',
                    array('current_date' => $current_date,
                    'pre_selected' =>$pre_selected),
                    $conn);
if (empty($home_team)){
    echo "No Match Selected for Today.";
} else {
    print_r($home_team);
}

How and where I use while loop for this query?

  • 写回答

4条回答 默认 最新

  • dshgdhdfcas30210 2013-07-07 03:31
    关注

    you don't need no while here

    function query($query, $bindings, $conn) {
        $stmt = $conn->prepare($query);
        $stmt-> execute($bindings);
        return $stmt->fetchAll();
    }
    $sql = 'SELECT home_team FROM premier_league WHERE match_date >= ?
                AND pre_selected = ? ORDER BY match_date LIMIT 5';
    $home_team = query($sql,array($current_date, $pre_selected), $conn);
    foreach ($home_team as $row) {
        echo $row['home_team']."<br>
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部