Schedule of commitments using fetchAll(PDO::FETCH_NAMED)

Asked

Viewed 194 times

-1

I am using fetchAll(PDO::FETCH_NAMED) to retrieve records from my database.

received the following array

Array ( 
        [0] => Array ( 
              [idAgenda] => 2 
              [dataAgenda] => 1996-02-14 
              [localAgenda] => teste 
              [cidadeAgenda] => São Paulo 
        ) 
        [1] => Array ( 
              [idAgenda] => 1 
              [dataAgenda] => 1996-02-14 
              [localAgenda] => teste2 
              [cidadeAgenda] => Santos 
        ) 
 ) 

Wondered how I get the data separately from this array?

  • I would do a foreach() to fetch these array values()

  • Yes, but I don’t know how to access [idAgenda],[dataAgenda]... I was trying something like this: $list([0] => ($list['idAgenda']); the array is in the list variable

  • You can try this oh: foreach($arr as $valor){ $idAgenda = $value["idAgenda"]; echo $idAgenda; }

  • I think what you asked is what I already answered here: http://answall.com/questions/31627/

2 answers

3

Good night, So there are several ways to rescue this information that I recommend is the foreach. However I will leave the two examples.

Example with foreach

<?php

//... daqui para trás é o seu código
$dados = $dbh->fetchAll(PDO::FETCH_NAMED);

foreach($dados as $dado) {
    echo $dado['idAgenda'] . '<br />';
    echo $dado['dataAgenda'] . '<br />';
}

Example with FOR

<?php

//... daqui para trás é o seu código
$dados = $dbh->fetchAll(PDO::FETCH_NAMED);
$quantidadeReg = count($dados);
for($i = 0; $i < $quantidadeReg; $i++) {
    echo $dados[$i]['idAgenda'] . '<br />';
    echo $dados[$i]['dataAgenda'] . '<br />';
}

2


Good night,

Here is an example of how you will redeem the values.

foreach ($array as $value) {
    //$value se tornará um array
    $a = $value["item"];
}

There’s a beast in there!

  • 1

    That’s it, thanks, much simpler than I thought.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.