getting the value from column, but returns null?

后端 未结 1 1159
醉梦人生
醉梦人生 2020-12-22 05:18

I\'m trying to get the value of \"rounds\" from the column rounds in my data base. So, I want to get the value which is a number of a field for each debate/post. Based on th

1条回答
  •  误落风尘
    2020-12-22 05:45

    I used PDOs. Your mistake was in the assignment of $rounds. And I cleaned up your code for better readability:

    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 '

    Round ' . $round . ' (Pro)


    Round ' . $round . ' (Con)


    Number of Rounds ' . $cnt . '

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

    0 讨论(0)
提交回复
热议问题