以下は私のテーブルから複数のデータを取得するために使用している関数のコードですが、bind_result($ array [0]、...、..)を使用してフィールドの数に応じて自動的に生成します私はクエリで選択しています。例えばPHPとMYSQLi - 配列にループとストアを使用してパラメータをバインドしますか?
..
$query=select a,b,c,d,e from table;//selecting 5 fields
......
$stmt->execute();$stmt->bind_result($retrieve[0],$retrieve[1],$retrieve[2],$retrieve[3],$retrieve[4]);
(5つの値についてbind_resultが自動的に生成されなければならない) ヘルプが...おかげ
$query="SELECT comment, userid,UNIX_TIMESTAMP(dtime)
FROM comment_updates
WHERE updateid=46546
ORDER BY dtime DESC
LIMIT 10 ";
if($stmt = $this->conn->prepare($query)) {
$stmt->execute();
$stmt->bind_result($comments[0],$comments[1],$comments[2]);
$i=0;
while($stmt->fetch()){
$i++;
$name='t'.$i;
$$name = array($comments[0],$comments[1],$comments[2]);
}
return array($i,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10);
$stmt->close();
}