简体   繁体   中英

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.

Code:

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

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

}

您应该只使用isbn数字,将mysql_fetch_assoc()与while循环一起使用。

If $db is a PDO object you can use

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

PDOStatement::fetchAll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM