duanmu8911 2016-10-29 19:03
浏览 16
已采纳

显示MYSQL PHP的唯一值

I am trying to get the isbn number of a book from a database, but with my command it is giving me an associative array.

How do I get it to return just the isbn number in the array.

Code:

function view_all_names($db)
{
$query = "SELECT  isbn from books";

$statement = $db->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$statement->closeCursor();
return $result;      

}
  • 写回答

2条回答 默认 最新

  • dpdt79577 2016-10-29 19:52
    关注

    If $db is a PDO object you can use

    $result = $statement->fetchAll(PDO::FETCH_COLUMN);
    

    PDOStatement::fetchAll

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?