sql >> Database teknologi >  >> RDS >> Mysql

henter værdien fra kolonne, men returnerer null?

Jeg brugte PDO s. Din fejl var i tildelingen af ​​$rounds .Og jeg ryddede op i din kode for bedre læsbarhed:

<?php
$servername = "";
$dbname = "";
$username = "";
$password = "";

$pdo = NULL;

try
{
  $pdo = new PDO('mysql:host=' . $servername . ';dbname=' . $dbname, $username, $password);
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
  die("Connection failed: " . $exception->getMessage());
}

$rounds = []; // array we want to save all the rounds to

// the database
$query = "SELECT rounds, COUNT(*) AS cnt FROM vf_Discussion GROUP BY rounds ORDER BY rounds";
$statement = $pdo->prepare($query);
$statement->execute();

$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);

foreach($rows as $row)
{
  $rounds[] = ['name' => $row['rounds'], 'count' => $row['cnt']];
}

foreach($rounds as $round)
{
  $name = $round['name'];
  $cnt = $round['cnt'];

  echo '<h2 class="CommentHeading">Round ' . $round . ' (Pro)</h2> <br> <h2 class="CommentHeading">Round ' . $round . ' (Con)</h2> <br> <h2 class="CommentHeading">Number of Rounds ' . $cnt . '</h2>';

  foreach($Sender->Data('Answers') as $Row)
  {
    $Sender->EventArguments['Comment'] = $Row;
    WriteComment($Row, $Sender, Gdn::Session(), 0);
  }
}
?>



  1. Hvordan rake db:drop og rake db:create på Heroku?

  2. mysql root adgangskode hvile

  3. Sequelize og peer-godkendelse til Postgres?

  4. TypeError:Kan ikke kalde metode 'forespørgsel' af null - når du kalder pg.connect med Heroku node.js