SAVERSVILLE SAVERSVILLE - 1 month ago 10
MySQL Question

display unique values from 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.
Here is my code

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

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

}

Answer

If $db is a PDO object you can use

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

PDOStatement::fetchAll