0
这是代码,我有foreach循环重复第一行
<?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] => [email protected] [submitted_date] => 1372030166))
然后显示echo
该行,然后重新开始,并出现了两次重复的第一行
Array ([0] => Array ([id] => 1 [username] => ccarson030308 [amount] => 5.00 [processor] => PayPal [email] => [email protected] [submitted_date] => 1372030166) [1] => Array ([id] => 2 [username] => tatsu91 [amount] => 5.00 [processor] => PayPal [email] => [email protected] [submitted_date] => 1372030166))
这应该是它开始的唯一事情,我的for
循环中是否有问题?我通常不会循环for
和foreach
,但它似乎是我尝试做的最好的方法,但我失败了。
不添加追加[]
我得到的 Warning: Illegal string offset 'amount' Warning: Illegal string offset 'email'
如果我不加追加,我得到许多错误,这就是为什么我添加了附加到开始与 '警告:非法字符串偏移'金额' '警告:非法字符串偏移'电子邮件' 它重复这些错误12次只是2行 – kira423
@ kira423:如果你添加它,你也会得到错误。所以不要随意更改不起作用的代码,而是正确调试它。非法字符串偏移意味着'$ row'不是数组。找出为什么。 – Jon
我在调试它不是一个随机的变化,我只是在提问之前尝试一种新方法,以确保我确实需要帮助。 – kira423