H
H
HeartOfProgrammer2015-08-18 12:08:12
PHP
HeartOfProgrammer, 2015-08-18 12:08:12

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

2 answer(s)
A
Alexey Ukolov, 2015-08-18
@HeartOfProgrammer

the script outputs only the title row in the news table

"Indeed, what is the reason for such strange behavior?" - Alexey Ukolov asked with obvious sarcasm in his voice.

A
Almik Oh! Give me a guitar, 2015-08-18
@almyk

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 question

Ask a Question

731 491 924 answers to any question