0
votes

Hi all I apologize that this question may be extremely simple but please be patient with me, I am a total newbie to PHP. I have created a query and used PDO to return the result to variable -> the result returns the following output - I have used the PDO::FETCH_ASSOC parameter. could anyone tell me how to take each column name and save the results to a separate array - the fetchColumn() feature also doesn't resolve my issue:

Array (
    [0] => Array (
        [BookName] => booky wooky
        [BookCode] => B1010
    )
    [1] => Array (
        [BookName] => dummybook
        [BookCode] => B1345
    )
    [2] => Array (
        [BookName] => OOP: The Basics
        [BookCode] => B2905
    )
)

Sorry if my question doesn't make sense - to put it briefly - I want to know how I can separate the arrays above and remove the SQL column names.

Any help would be much appreciated and I apologize if this is extremely obvious

1
Your question would make a lot more sense if you gave an example of the desired resultPhil

1 Answers

3
votes

You can iterate over your result set and extract the individual fields.

$book_names = []; # or array(); if you are using PHP 5.3 or older.
foreach($result_set as $row) {
  $book_names[] = $row['BookName'];
}