我现在正在跳转到 mysqli/PDO,并将 SELECT 循环从“旧”方法转换为 mysqli。
“旧”方法:
$query="SELECT * FROM transactions ORDER BY id DESC LIMIT 10";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"name");
$f2=mysql_result($result,$i,"surname");
$f3=mysql_result($result,$i,"pcode");
$f4=mysql_result($result,$i,"transaction_id");
$f5=mysql_result($result,$i,"articles");
$f6=mysql_result($result,$i, "delivery");
//echo out to table here
$i++;
}
我已经了解了基本的 mysqli 查询,然后简单地尝试复制上面的 while 循环:
if ($pending_stmt=$mysqli->prepare('SELECT * FROM transactions WHERE status = ?')) {
$pending_stmt->bind_param('s', $status); //$status is set prior to if statement
$pending_stmt->execute();
$pending_stmt->store_result();
$pending_stmt->fetch_all();
$rows=$pending_stmt->num_rows();
$i=0;
while ($i < $rows) {
$f1=$pending_stmt->fetch($i,'pcode');
//echo out to table here
$i++;
}
}
不用说,它不起作用......经过大量搜索,我想知道是否有人愿意给我一些指示。