I have function which selects data from MySQL database:
function get_articles( $id ){
global $pdo;
$query = $pdo->prepare('
SELECT id_news, number, title, content
FROM page_news
WHERE number = :id
');
$query->execute( array( ':id' => $id ) );
return $query->fetchAll( PDO::FETCH_OBJ );
}
Next, I am creating a new variable:
$articles = get_articles( $_GET['id'] );
If I print_r($articles); everything seems okay. Required table is printed:
Array
(
[0] => stdClass Object
(
[id_news] => 226
[number] => 14
[title] => Cupcake ipsum dolor sit. Amet cotton candy I love I love bonbon.
[content] => I love cotton candy I love sweet roll halvah cheesecake oat cake pastry halvah. Bonbon danish I love lemon drops chocolate candy canes jelly beans jelly-o. Tiramisu topping donut chocolate cake. Candy canes wafer icing cheesecake candy applicake tiramisu.
I love chocolate sugar plum chocolate bar. Jujubes wafer lollipop marshmallow halvah sesame snaps brownie icing sweet roll.
)
)
But when I am trying to echo any value with eg.:
echo "<p>{$articles->content}</p>";
nothing is being printed (an empty paragraph is created) and I cannot find out where the problem is.
I have another similar function which selects different data in the same way and printing out works perfectly.
It’s array. You must use