这是我拥有的代码
<?php
$checkbox = $_REQUEST['checkbox'];
for($i=0; $i<count($_REQUEST['checkbox']); $i++){
$del_id = $checkbox[$i];
$get_info=$db->prepare("SELECT * FROM `pending_payments` WHERE `id` = ?");
$get_info->bind_param('i', $del_id);
$get_info->execute();
$result = $get_info->get_result();
$info[] = $result->fetch_assoc();
foreach($info as $row){
$amount = $row['amount'];
$email = $row['email'];
echo"
<input type='text' style='height: 35px;' name='Amount[]' value='".$amount."' />
<input type='text' style='height: 35px;' name='EmailAddress[]' value='".$email."' /><br />
";
}
}
?>
我遇到的问题是它正在复制它找到的第一行。我在数据库中有 2 个条目,它在进行第三行之前重复第一行两次,当我print_r
$info
给我这个时
Array ( [0] => Array ( [id] => 1 [username] => ccarson030308 [amount] => 5.00 [processor] => PayPal [email] => ccarson030308@gmail.com [submitted_date] => 1372030166 ) )
然后显示该echo
行然后重新开始并显示
Array ( [0] => Array ( [id] => 1 [username] => ccarson030308 [amount] => 5.00 [processor] => PayPal [email] => ccarson030308@gmail.com [submitted_date] => 1372030166 ) [1] => Array ( [id] => 2 [username] => tatsu91 [amount] => 5.00 [processor] => PayPal [email] => sheynever@yahoo.com [submitted_date] => 1372030166 ) )
这应该是它开始显示的唯一内容,我的for
循环中是否有问题?我通常不循环for
,foreach
但这似乎是我想做的最好的方法,但我以某种方式失败了。
在不添加附加的情况下,[]
我得到 12 个错误
Warning: Illegal string offset 'amount'
Warning: Illegal string offset 'email'