1

Using Medoo how do I echo the values from the select query currently this is what I am doing using the example from the docs.

$data = $database->select('names', [
'name','nameId'
], [
'nameId' => 50
]);

echo json_encode($data);

the result is:

[{"name":"Allen","nameId":"50"}]

How can I echo each one without json_encode?

I have tried:

$data['name']

But that doesn't work.

Abu Nooh
  • 846
  • 4
  • 12
  • 42

2 Answers2

3

If it's one row you're looking to fetch, use Get instead of Select

      $names = $db->get('names',['name','nameId'],['nameId'=>50]);

then use

      $name = $names['name'];
      $nameId = $names['nameId'];

although you don't need the nameId since your condition is based on it so simply:

      $name = $db->get('names','name',['nameId'=>50]);
nitrex
  • 522
  • 6
  • 16
2

Loop and print.

foreach ($data as $row) {
    // echo code here...
    // echo $row['name'];
}

http://php.net/manual/en/control-structures.foreach.php

0kay
  • 433
  • 4
  • 7