提问人:MK Smith 提问时间:7/31/2017 最后编辑:Funk Forty NinerMK Smith 更新时间:7/31/2017 访问量:1379
PDO 在 WHILE 循环中使用 fetchAll 时抛出通知:未定义索引
PDO throws an Notice: Undefined index when using fetchAll in a WHILE loop
问:
我是PHP世界的新手,在这里我需要一些帮助。 我正在尝试从数据库中提取数据,我正在使用 PDO 来做到这一点。 我有以下PHP代码没有成功,抛出错误通知:
$pairingsistem='1';
$pecahan='1';
if($pairingsistem == "1"){
$skrg=time();
$tablaz = $pdo->query("SELECT * FROM tb_gh where saldo > 0 and status='pending' order by id ASC limit 0,1");
while ($registroz = $tablaz ->fetchAll(PDO::FETCH_ASSOC)){
//use $results
$kurirz=$registroz["username"]; //line 47 starts here
$biayaz=$registroz["saldo"];
$idnyaz=$registroz["id"];
$bankeem=$registroz["bank"];
$norekeem=$registroz["norek"];
$bitcoineem=$registroz["bitcoin"];
$pmeem=$registroz["perfectmoney"];
$fasapayeem=$registroz["fasapay"];
$namaeem=$registroz["nama"];
$phoneeem=$registroz["phone"];
$emaileem=$registroz["email"];
$paketzeem=$biayaz*$pecahan;
$surabaya=$paketzeem/$pecahan;
//shortline
注意:未定义索引:用户名 /home/u427750052/public_html/automatch.inc.php 47号线
注意:未定义索引:saldo in /home/u427750052/public_html/automatch.inc.php 上线 48
注意:未定义的索引:id /home/u427750052/public_html/automatch.inc.php 49 行
注意:未定义索引:银行入 /home/u427750052/public_html/automatch.inc.php 上线 50
注意:未定义索引:norek in /home/u427750052/public_html/automatch.inc.php 上线 51
注意:未定义指数:比特币 /home/u427750052/public_html/automatch.inc.php 上线 52
注意:未定义指数:perfectmoney /home/u427750052/public_html/automatch.inc.php 上线 53
注意:未定义索引:fasapay in /home/u427750052/public_html/automatch.inc.php 上线 54
注意:未定义索引:nama in /home/u427750052/public_html/automatch.inc.php 55号线
注意:未定义索引:电话输入 /home/u427750052/public_html/automatch.inc.php 上线 56
注意:未定义的索引:电子邮件 /home/u427750052/public_html/automatch.inc.php 上线 57
这是警告。尽管到目前为止,我已经在我的知识范围内解决了所有问题。
答:
你把你扔在这里。您需要循环访问或遍历返回的结果。while
fetchAll
fetch
fetchall
所以要么:
while ($registroz = $tablaz ->fetch(PDO::FETCH_ASSOC)){
或
$registroz = $tablaz ->fetchAll(PDO::FETCH_ASSOC);
foreach($registroz as $row) {
但是,由于您让它只返回 1 行,因此您不需要循环或 .fetchall
$registroz = $tablaz ->fetch(PDO::FETCH_ASSOC);
应该可以解决问题。
评论
$registroz
$kurirz=$registroz[0]["username"];
评论
fetchAll
undefined index