来自Select的Medoo回声值

时间:2018-01-11 21:21:43

标签: php pdo medoo

使用Medoo如何回应select查询中的值,这是我正在使用文档中的示例进行的操作。

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

echo json_encode($data);

结果是:

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

如何在没有json_encode的情况下回复每一个?

我试过了:

$data['name']

但这不起作用。

2 个答案:

答案 0 :(得分:2)

循环并打印。

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

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

答案 1 :(得分:2)

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