douyo770657 2017-07-31 00:43
浏览 81
已采纳

在WHILE循环中使用fetchAll时,PDO会抛出一个注意:未定义的索引

I'm new in the PHP world and I need a bit of help here. I'm trying to extract a data from database, I'm using PDO to do it. I have the following PHP code without success, throwing back error notice:

$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

Notice: Undefined index: username in /home/u427750052/public_html/automatch.inc.php on line 47

Notice: Undefined index: saldo in /home/u427750052/public_html/automatch.inc.php on line 48

Notice: Undefined index: id in /home/u427750052/public_html/automatch.inc.php on line 49

Notice: Undefined index: bank in /home/u427750052/public_html/automatch.inc.php on line 50

Notice: Undefined index: norek in /home/u427750052/public_html/automatch.inc.php on line 51

Notice: Undefined index: bitcoin in /home/u427750052/public_html/automatch.inc.php on line 52

Notice: Undefined index: perfectmoney in /home/u427750052/public_html/automatch.inc.php on line 53

Notice: Undefined index: fasapay in /home/u427750052/public_html/automatch.inc.php on line 54

Notice: Undefined index: nama in /home/u427750052/public_html/automatch.inc.php on line 55

Notice: Undefined index: phone in /home/u427750052/public_html/automatch.inc.php on line 56

Notice: Undefined index: email in /home/u427750052/public_html/automatch.inc.php on line 57

this has been the warnings. Though I have troubleshot all I could within the scope of my knowledge on this so far.

  • 写回答

1条回答 默认 最新

  • duanjia6959 2017-07-31 00:55
    关注

    Your while and fetchAll are throwing you off here. You either need to loop a fetch or fetchall then iterate over the returned result.

    So either:

    while ($registroz = $tablaz ->fetch(PDO::FETCH_ASSOC)){ 
    

    or

    $registroz = $tablaz ->fetchAll(PDO::FETCH_ASSOC);
    foreach($registroz as $row) {
    

    but since you have it returning only 1 row you don't need a loop or fetchall.

    $registroz = $tablaz ->fetch(PDO::FETCH_ASSOC);
    

    should do the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)