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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题