Reputation: 111
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.
Upvotes: 3
Views: 1444
Reputation: 23880
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.
Upvotes: 3