mysql - Php prepare method where should I use While loop -
i new php prepare method, need use while loop in following code.
here query function
function query($query, $bindings, $conn) { $stmt = $conn->prepare($query); $stmt-> execute($bindings); $result = $stmt->fetchall(); return $result ? $result : false; }
and query
$home_team = query('select home_team premier_league match_date >= :current_date , pre_selected = :pre_selected order match_date limit 5', array('current_date' => $current_date, 'pre_selected' =>$pre_selected), $conn); if (empty($home_team)){ echo "no match selected today."; } else { print_r($home_team); }
how , use while loop query?
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 premier_league match_date >= ? , pre_selected = ? order match_date limit 5'; $home_team = query($sql,array($current_date, $pre_selected), $conn); foreach ($home_team $row) { echo $row['home_team']."<br>\n"; }
Comments
Post a Comment