开发者

mySQLi Prepared Statement: Fetch() Failing

My query keeps failing to fetch. It works just fine in my SQL Console so I'm at a loss. Here's the code.

$q_st = "SELECT tryouts.playerFName,tryouts.playerLName,tryouts.mainEmail,
tryouts.secondEmail, players.number FROM tryouts LEFT JOIN p开发者_Go百科layers ON
players.userID=tryouts.userID WHERE players.team = ? 
ORDER BY tryouts.playerLName";

$stmt = $GLOBALS['m']->prepare($q_st);
$stmt->bind_param("s",$GLOBALS['c_team']);
$stmt->execute();
$stmt->bind_result($pfn,$pln,$em,$em2,$num);

if($stmt->fetch()==false)
{
echo($GLOBALS['m']->error . $GLOBALS['m']->sqlstate ." Haha It doesn't work and YOU     don't know why!!!");
}
else
{
while($stmt->fetch())                  {
static $count3;
echo ($pfn . " " . $pln . " " . $num . "<input type=\"checkbox\" class=\"player\" value=\"" . $em ."\"  id=\"player ". ++$count3 . "\"><br />");
}              
}

Result is "00000 Haha It doesn't work and YOU don't know why!!!"

I've tested all the other stmt parameters and they all come through with success. Any ideas?


As the mysqli_stmt_fetch() method can return null and false you have to use === to check if the returned value is false or not (or if it is null or not). Otherwise you interpret the return value null as an error code, which it isn't.

Additionally your code reads one row from the result with your first fetch() call, but you don't handle the returned row in any way. You are dropping the first row of your result set which might not be something you want.

If you want to know how many rows the result set has use mysqli_stmt_num_rows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜