Answer the question
In order to leave comments, you need to log in
Why does PDO query not want to output content?
There is a site on the local server, created the pdo_db database, and created tables there news which has 5 lines (id, title, content, add_date, author). The script below outputs only the title row in the news table. The remaining content, add_date, author does not display
$USER_DB = 'HeartProgrammer';
$PASS_DB = '123321';
try {
$PDO = new PDO('mysql:host=localhost;dbname=pdo_db', $USER_DB, $PASS_DB);
foreach($PDO->query('SELECT title FROM news') as $row) { ?>
<h1 class="title"><?=$row['title']?></h1>
<p class="content"><?=$row['content']?></p>
<p class="add_date">Дата публикации: <?=$row['add_date']?></p>
<p class="author">Автор: <?=$row['author']?></p>
<? }
$PDO = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Answer the question
In order to leave comments, you need to log in
the script outputs only the title row in the news table
Hello, the error is obvious.
note
Here you only want to get TITLE from NEWS table , try this SELECT * FROM news But you have to look at correct column names
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question