I have a prepared statement to draw information from a database. There are 3 fields of information drawn from the database and an unknown number of rows.
I have a 'while' loop to define what should happen to the information gained from each row. I would like to create an array for the 3 fields of information to sit in for each row, then an array for all of these arrays to sit in (i.e. a 2D array).
Here's my code so far:
$bArray = [];
$bList = $mysqli->prepare('SELECT blog_title,blog_date,blog_id FROM cms_blog');
$bList->execute();
$bList->bind_result($bListTitle,$bListDate,$bListId);
while ($bList->fetch()) {
$bArray['bTitle']=$bListTitle;
$bArray['bDate']=$bListDate;
$bArray['bId']=$bListId;
}
I would like the array to look something like this once complete:
Array (
Array (
[blogTitle] => First title
[blogDate] => First date
[blogId] => First ID
)
Array (
[blogTitle] => Second title
[blogDate] => Second date
[blogId] => Second ID
)
)
Is there a way to write this? I only need key pairs for the inner arrays.