Abu Nooh
Abu Nooh

Reputation: 856

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.

Upvotes: 1

Views: 831

Answers (2)

nitrex
nitrex

Reputation: 542

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

Upvotes: 3

0kay
0kay

Reputation: 433

Loop and print.

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

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

Upvotes: 2

Related Questions