Non grata person list using php

4127 views php
4

I wanted to make a banlist, non-grata person list. Here's what I got.

  include_once 'info.php';  

    $query = $config -> prepare("SELECT `banID`, `user_banned`, `ban_reason`, `ban_time`, `user_banner`, `ban_timestamp` FROM `samp_ban` ORDER BY `banID` ASC LIMIT 10");  
    if($query -> execute())  
    {  
        $query_results = $query->fetchAll();

    }


  <div class="table-responsive">
    <table id="dataTable1" class="table table-bordered table-striped-col">
      <thead>
        <tr>
          <th>USER</th>
          <th>REASON</th>
          <th>TIME</th>
          <th>ADMIN</th>
          <th>DATA</th>
        </tr>
      </thead>
      <?php foreach( $query_results as $query_result ) { 
                            if($query_result["ban_time"] == 0) { $query_result["ban_time"] = "Permanent"; } ?>  

      <tbody>
        <tr>
          <td><?php echo $query_result["user_banned"]; ?></td>
          <td><?php echo $query_result["ban_reason"]; ?></td>
          <td><?php echo $query_result["ban_time"]; ?> </td>
          <td><?php echo $query_result["user_banner"];  ?></td>
          <td><?php echo $query_result["ban_timestamp"];  ?></td>
        </tr>


      </tbody>
    </table>
  </div>

instead of showing every non grata list, it shows only the first one from the mysql. Why it does that and not showing every person from mysql table?

Later Edit: I found that it shows every person from banlist but it won't show inside the table. Later edit 2: I solved it. I had to move above.

answered question

1 Answer

4

You need to close the foreach loop after you closing row tag.

include_once 'info.php';  

$query = $config -> prepare("SELECT `banID`, `user_banned`, `ban_reason`, `ban_time`, `user_banner`, `ban_timestamp` FROM `samp_ban` ORDER BY `banID` ASC LIMIT 10");  
if($query -> execute())  
{  
    $query_results = $query->fetchAll();

}


  <div class="table-responsive">
    <table id="dataTable1" class="table table-bordered table-striped-col">
  <thead>
    <tr>
      <th>USER</th>
      <th>REASON</th>
      <th>TIME</th>
      <th>ADMIN</th>
      <th>DATA</th>
    </tr>
  </thead>
  <?php foreach( $query_results as $query_result ) { 
                        if($query_result["ban_time"] == 0) { $query_result["ban_time"] = "Permanent"; } ?>  

  <tbody>
    <tr>
      <td><?php echo $query_result["user_banned"]; ?></td>
      <td><?php echo $query_result["ban_reason"]; ?></td>
      <td><?php echo $query_result["ban_time"]; ?> </td>
      <td><?php echo $query_result["user_banner"];  ?></td>
      <td><?php echo $query_result["ban_timestamp"];  ?></td>
    </tr>

  <?php } ?>
  </tbody>

posted this

Have an answer?

JD

Please login first before posting an answer.