-1
我的功能:爲什麼這個函數返回一個結束= 1的行?
function fetchAllGames($limit=9, $page=1, $isEnded="")
{
global $mysqli,$db_table_prefix;
if($isEnded!=""){$myWhere="WHERE ended=".$isEnded." ";}else{$myWhere="";}
$offset=($page - 1) * $limit;
$stmt = $mysqli->prepare("SELECT
created_timestamp,
end_timestamp,
winner_userid,
ended,
name,
game_uniqID,
game_id,
img
FROM ".$db_table_prefix."game
".$myWhere."
LIMIT ".$limit."
OFFSET ".$offset);
$stmt->execute();
$stmt->bind_result($created_timestamp, $end_timestamp, $winner_userid, $ended, $name, $game_uniqID, $game_id, $gameImg);
while ($stmt->fetch()){
$row[] = array('created_timestamp' => $created_timestamp, 'end_timestamp' => $end_timestamp, 'winner_userid' => $winner_userid, 'ended' => $ended, 'name' => $name, 'game_uniqID' => $game_uniqID, 'game_id' => $game_id, 'gameImg' => $gameImg);
}
$stmt->close();
if (isset($row)){
return ($row);
}
}
如果我通過$allGames = fetchAllGames(9,1,0);
叫它然後返回止帶= 0和行,結束= 1兩行,如果我通過$allGames = fetchAllGames(9,1,1);
叫它它結束= 1只返回行。我無法弄清楚爲什麼。我錯過了什麼嗎?
因爲0 =「」在劇組結束後,它拿起'else {$ myWhere =「」;}' – Drew
你能澄清一點嗎? –
不合邏輯,沒有。但是你的代碼似乎就是這種情況。如果你傳遞0,你可以vardump'$ myWhere'嗎? – Drew