I am trying to create a single array from a db table that has few rows like:
--------------
id | name
--------------
1 | value 1
2 | value 2
3 | value 3
--------------
I want the created array to be as simple as possible like value1,value2,value3
I am using this function
function getAll()
{
//select all data
$sql = "SELECT name FROM " . $this->table_name . " ORDER BY id";
$prep_state = $this->db_conn->prepare($sql);
$prep_state->execute();
$row = $prep_state->fetch(PDO::FETCH_ASSOC);
$this->name = $row['name'];
}
Is there a simple way to do it, perhaps with another PDO Mode like for example is done with PDO::FETCH_UNIQUE, or a should take a different approach?
UPDATE - This way it worked (thanks to @u_mulder)
function getAll()
{
$sql = "SELECT name FROM " . $this->table_name . " ORDER BY id";
$prep_state = $this->db_conn->prepare($sql);
$prep_state->execute();
$names = $prep_state->fetchAll(PDO::FETCH_COLUMN, 0);
return(implode(",",$names));
}