我试图找出如何在另一个准备好的staments循环中运行第二个预准备语句。不是最佳,但不知道我怎么能解决这个问题......
以下是我的尝试:
$stmt = $mysqli->stmt_init();
### GET THE CURRENT USERS FRIENDS ###
$sql = "SELECT f.fk_user_id2
, u.username
, u.profileimg FROM ".$prefix."_friends f
INNER JOIN ".$prefix."_users u
ON f.fk_user_id2 = u.id
WHERE f.fk_user_id1 = ? ORDER BY u.username ASC";
if($stmt->prepare($sql)){
$stmt->bind_param('i',$playerid);
$stmt->execute();
$stmt->bind_result($userPoints);
while ($stmt->fetch()){
$friendid = $row1['fk_user_id2'];
$friendname = $row1['username'];
if(empty($row1['profileimg'])){
$profileimg = 'http://duefmun.dk/profileimages/noimage.png';
} else {
$profileimg = 'http://duefmun.dk/profileimages/'.$row1['profileimg'];
}
### GET THE HISTORY ###
$sql1 = mysql_query("SELECT wins, games FROM ".$prefix."_newversus WHERE fk_player=? AND fk_opponent=?");
if($stmt->prepare($sql1)){
$stmt->bind_param('ii',$playerid,$friendid);
$stmt->execute();
$stmt->bind_result($wins,$games);
$stmt->fetch();
if($games == 0){
$history = $languagestring[165];
} else {
$history = $languagestring[168].' '.$wins.' '.$languagestring[169].' '.$games.' '.$languagestring[170];
}
}
$string .= $friendname.','.$friendid.','.$history.','.$profileimg.'^';
}
}
$string = substr($string,0, (strlen($string)-1));
echo $string.'%';
$stmt->close();
也许有可能内连接第二个语句,但不知道如何。请提前帮助和感谢: - /
答案 0 :(得分:0)
这不是一个准备好的陈述是你的问题,而只是一个变量
在这种情况下,你只是重写你的变量$ stmt
给它第二个循环的另一个名称(并检查其他所有变量)