Search code examples
phppdomedoo

Medoo echo values from Select


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.


Solution

  • 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]);