doulidai6316 2013-07-07 11: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 11: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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度