0

I'm doing var_dump since I started to learn PHP/PDO when I want to display the SQL datas, like:

$tickets = $db->query('SELECT * FROM tickets')->fetchAll();
var_dump($tickets);

And it shows everything.

But now I'd like to echo a list of all tickets name, usually I would do an echo $tickets->name; but first it doesn't work with fetchAll(); and when I use fetch(); it returns only the last row

Noob question but all the answers I get are outdated and uses depreciated mysql, how can I just display the rows with PDO ?

Thanks !

Jonas
  • 121,568
  • 97
  • 310
  • 388
whitelamp
  • 37
  • 1
  • 5
  • what happens if you `var_dump($tickets);` you should an array of array or objects, then you can echo whatever you like – Dale Jun 07 '16 at 10:02
  • What one would normally do is call `fetch()` repeatedly, handling each record in turn, rather than loading the entire resultset into a PHP array. – eggyal Jun 07 '16 at 10:22

1 Answers1

1

PDO fetch_all default to fetching both numeric and associative arrays

$tickets = $db->query('SELECT * FROM tickets')->fetchAll();
foreach($tickets as $ticket) {
    echo $ticket['name'];
}
Dale
  • 10,384
  • 21
  • 34