Только в первой строке таблицы отображается!


Я запрашивая данные из таблицы таким образом:

    $sql = "SELECT * FROM `login` order by `userid` DESC";
$limite = mysqli_query($db, $sql);
while ($sql = mysqli_fetch_array($limite)) {
    $account_id = $sql['account_id'];
    $userid = $sql['userid'];
    $sex = $sql['sex'];
    $email = $sql['email'];
    $group_id = $sql['group_id'];
    $last_ip = $sql['last_ip'];
}
echo '
<table class="vertical-table th">
    <tr align="center">
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>ID</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Login</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Sexo</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Email</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Level</b></font></th>
      <th width="20%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>IP</b></font></th>
    </tr>
<tr align="center">
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#009900" size="2">'.$account_id.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>'.$userid.'</b></font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$sex.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$email.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#E41B17" size="2">'.$group_id.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#000099" size="2">'.$last_ip.'</font></p></td>
    </tr>
    </table>

Испытывая запрос непосредственно в базе данных работает отлично, но в этом страница возвращает только первую строку...

 1
Author: Wallace Maxters, 2015-03-25

3 answers

Будет отображать только значения последней записи, потому что их echo, после while, если хотите, чтобы печатать все записи играйте код внутри цикла.

while ($sql = mysqli_fetch_array($limite)) {
    $account_id = $sql['account_id'];
}
echo '
//... mais código
<p style="margin-top: 0; margin-bottom: 0">
<font face="Verdana" size="2"><b>'.$userid.'</b></font></p></td>

Может исправить при интерполяции PHP, HTML:

<table class="vertical-table th">
    <tr align="center">
      <th width="10%">ID/th>
      <th width="10%">Login</b>/th>
    </tr>

<?php
    $sql = "SELECT * FROM `login` order by `userid` DESC";
    $limite = mysqli_query($db, $sql);
    while ($sql = mysqli_fetch_array($limite)) {
       $account_id = $sql['account_id'];
       $userid = $sql['userid'];
?>
       <tr align="center">
          <td><?php echo $account_id; ?></td>
          <td><?php echo $userid; ?></td>
       </tr> 
<?php 
    } 
?>
</table>
 3
Author: rray, 2015-03-25 12:28:00

Использовать все данные, что видят, Базы Данных, вы должны распечатать их на всех итераций while, то есть, при наличии линий прийти Базы ты imprimes строки таблицы в HTML.

echo '
<table class="vertical-table th">
    <tr align="center">
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>ID</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Login</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Sexo</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Email</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Level</b></font></th>
      <th width="20%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>IP</b></font></th>
    </tr>
';    

$sql = "SELECT * FROM `login` order by `userid` DESC";
$limite = mysqli_query($db, $sql);
while ($sql = mysqli_fetch_array($limite)) {
    $account_id = $sql['account_id'];
    $userid = $sql['userid'];
    $sex = $sql['sex'];
    $email = $sql['email'];
    $group_id = $sql['group_id'];
    $last_ip = $sql['last_ip'];

    echo ' 
    <tr align="center">
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#009900" size="2">'.$account_id.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>'.$userid.'</b></font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$sex.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$email.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#E41B17" size="2">'.$group_id.'</font></p></td>
      <td>
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#000099" size="2">'.$last_ip.'</font></p></td>
    </tr>
   ';
}   
echo'</table>';
 3
Author: Jorge B., 2015-03-25 12:20:15

while - это команда, которая просматривает записи из запроса. Вам нужно ему в конкретной части table, которую хотите повторить, в вашем случае, будет что-то вроде:

echo '
<table class="vertical-table th">
   <tr align="center">
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>ID</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Login</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Sexo</b></font></th>
      <th width="10%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Email</b></font></th>
      <th width="25%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>Level</b></font></th>
      <th width="20%">
      <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>IP</b></font></th>
   </tr>
   ';

   while ($sql = mysqli_fetch_array($limite)) {
      $account_id = $sql['account_id'];
      $userid = $sql['userid'];
      $sex = $sql['sex'];
      $email = $sql['email'];
      $group_id = $sql['group_id'];
      $last_ip = $sql['last_ip'];

      echo '
      <tr align="center">
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#009900" size="2">'.$account_id.'</font></p></td>
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2"><b>'.$userid.'</b></font></p></td>
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$sex.'</font></p></td>
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" size="2">'.$email.'</font></p></td>
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#E41B17" size="2">'.$group_id.'</font></p></td>
         <td>
         <p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#000099" size="2">'.$last_ip.'</font></p></td>
      </tr>
      ';
   }
echo '</table>';
 2
Author: Dirty Old Man, 2015-03-25 12:26:15