douyo770657 2017-07-30 16: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-30 16: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部