PHP排行榜没有显示正确的方式

时间:2018-03-27 07:12:54

标签: php html css mysql foreach

我正在与我的数据库中的人进行leaderboard。我的网站是用PHP(PDO)构建的,问题是我不能让用户从数据库中出来以显示正确的方式。

我用来从数据库中获取信息的函数是:

public function get_klanten(){
    $getKlant = $this->database->query("SELECT * FROM klanten ORDER BY id ASC LIMIT 1");
    $klanten = $this->database->resultset();

    return $klanten;
}

enter image description here How it is now

我得到的问题是,它将每个记录放在一起,而不是在新行上添加LIMIT 1,但我希望第二个用户在这种情况下Amet也不在数据库。

带有这个的HTML是一个不同的文件,下面是代码。

<thead>
    <tr>
        <th>#</th>
        <th>Lid</th>
        <th><span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span></th>
        <th><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></th>
    </tr>
</thead>
<tbody>
    <tr>

        <?php
        $klantten = $app->get_klanten();

        foreach ($klantten as $klant) {
            echo '<td>' . $klant['id'] . ' </td>';
            echo '<td>' . $klant['voornaam'] . ' ' . $klant['achternaam'] . ' </td>';
            echo '<td>' . $klant['punten'] . ' </td>';
            echo '<td>' . $klant['punten'] . ' </td>';
        }
        ?>
    </tr> 

    <tr>
        <td>2</td>
        <td>amet</td>
        <td>456</td>
        <td>52</td>
    </tr>

奖金

<div class="col-md-6">
     <div class="well dash-box">
       <h2><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> Stel jezelf voor</h2>
       <h5><a href="https://tom.lbmedia.nl/onderwerp"> Laat wetn wie jij en je business zijn</a></h5>
   </div>
   </div>
  <div class="col-md-6">
  <div class="well dash-box">
  <h2><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> 12</h2>
  <?php
  $toppics = $app->get_topics();
  $i = 0;
  foreach ($toppics as $topic) {
 echo '<a href="#section' . $i++ . '">' . $topic['onderwerp'] . '</a>';
  }
  ?>
  </div>
  </div>

功能:

  public function get_topics(){
        $getTopic = $this->database->query("SELECT * FROM topics ORDER BY id DESC");
        $topics = $this->database->resultset();

        return $topics;

    }

我希望这也是新块中的每条记录。所以每个topic都是一个新块。您现在可以看到2个块我希望每个块从数据库中获取不同的记录

What it looks like     1https://i.stack.imgur.com/lH8oz.png

1 个答案:

答案 0 :(得分:1)

从查询中删除限制1,然后移动TR标记,使其位于foreach循环中。

   <?php
   $klantten = $app->get_klanten();

foreach ($klantten as $klant) {
  echo '<tr>';
  echo '<td>' . $klant['id'] . ' </td>';
  echo '<td>' . $klant['voornaam'] . ' ' . $klant['achternaam'] . ' </td>';
  echo '<td>' . $klant['punten'] . ' </td>';
  echo '<td>' . $klant['punten'] . ' </td>'; 
  echo '</tr>';
   }

   ?>