2017-03-08 3 views
-1

私はこの問題を抱えています。ここではすべてのユーザーの詳細をすべて印刷していますが、下の写真からわかるように、これによって、最初の名前のボックスの中には、50ピクセル幅のものしか表示されないものもあれば、より広いものもあります。テーブルが正しく表示されず、行が揃っていません

enter image description here

この問題を修正し、各エントリの詳細を整列する方法はありますか? 私は以下のPHPコードを添付していますので、あなたはそれを見ることができます。このすべてに加えて、事前

while($users=mysqli_fetch_assoc($getUsers)){ 
     echo '<table border="1" cellpadding="1" cellspacing="1" width="80%" style="margin: 0 auto">'; 
     echo '<tr class="allUsers">'; 
     echo '<th>Username</th>'; 
     echo '<th>First name</th>'; 
     echo '<th>Last name</th>'; 
     echo '<th>Email</th>'; 
     echo '<th>Year group</th>'; 
     echo '<th>Subject 1</th>'; 
     echo '<th>Subject 2</th>'; 
     echo "<th>Subject 1's teacher</th>"; 
     echo "<th>Subject 2's teacher</th>"; 
     echo '<th>Privilege</th>'; 
     echo '<th>Own database</th>'; 
     echo '</tr>'; 

     echo '<tr>'; 
     echo '<td>'.$users['username'].'</td>'; 
     echo '<td>'.$users['first_name'].'</td>'; 
     echo '<td>'.$users['last_name'].'</td>'; 
     echo '<td>'.$users['email'].'</td>'; 
     echo '<td>'.$users['year_group'].'</td>'; 
     echo '<td>'.$users['subject'].'</td>'; 
     echo '<td>'.$users['subject2'].'</td>'; 
     echo '<td>'.$users['teacher'].'</td>'; 
     echo '<td>'.$users['teacher2'].'</td>'; 
     echo '<td>'.$users['is_admin'].'</td>'; 
     echo '<td>'.$users['own_database'].'</td>'; 
     echo '</tr>'; 
     echo '</table>'; 

おかげで、私はちょうどそのちょうど、ユーザーのすべての詳細を一覧表示する、上部のヘッダを一度だけ表示することができます方法はありますか?

答えて

2

実際に1つだけ必要な場合は、ユーザーごとに個別のテーブルを作成しています。ループから<table>タグとヘッダを分離してみてくださいので、彼らは一度だけエコーされます:

echo '<table border="1" cellpadding="1" cellspacing="1" width="80%" style="margin: 0 auto">'; 
echo '<tr class="allUsers">'; 
echo '<th>Username</th>'; 
echo '<th>First name</th>'; 
echo '<th>Last name</th>'; 
echo '<th>Email</th>'; 
echo '<th>Year group</th>'; 
echo '<th>Subject 1</th>'; 
echo '<th>Subject 2</th>'; 
echo "<th>Subject 1's teacher</th>"; 
echo "<th>Subject 2's teacher</th>"; 
echo '<th>Privilege</th>'; 
echo '<th>Own database</th>'; 
echo '</tr>'; 

while($users=mysqli_fetch_assoc($getUsers)){ 
    echo '<tr>'; 
    echo '<td>'.$users['username'].'</td>'; 
    echo '<td>'.$users['first_name'].'</td>'; 
    echo '<td>'.$users['last_name'].'</td>'; 
    echo '<td>'.$users['email'].'</td>'; 
    echo '<td>'.$users['year_group'].'</td>'; 
    echo '<td>'.$users['subject'].'</td>'; 
    echo '<td>'.$users['subject2'].'</td>'; 
    echo '<td>'.$users['teacher'].'</td>'; 
    echo '<td>'.$users['teacher2'].'</td>'; 
    echo '<td>'.$users['is_admin'].'</td>'; 
    echo '<td>'.$users['own_database'].'</td>'; 
    echo '</tr>'; 
} 
echo '</table>'; 
+0

どうして私はこれについて考えなかったのですか?ハハ:D大変ありがとう! – leveeee

2

をすべての2行は、独自のテーブルであるように見えます。 <table>のものではなく、<tr>の繰り返しを行います。

+0

ご協力いただきありがとうございます! – leveeee

関連する問題