重複したエントリを配列から削除してテーブルに表示しようとしています。ここで2つのデータに基づいてテーブルの行を削除します
は、私が使用するデータフォーマットの例である:
array (size=4)
0 =>
array (size=5)
'Statut' => string 'REFUSED' (length=5)
'Username' => string 'name' (length=4)
'Nom' => string 'firstname' (length=9)
'Email' => string '[email protected]' (length=14)
'Regularisation' => string 'N' (length=1)
1 =>
array (size=5)
'Statut' => string 'REFUSED' (length=5)
'Username' => string 'name' (length=4)
'Nom' => string 'firstname' (length=9)
'Email' => string '[email protected]' (length=14)
'Regularisation' => string 'N' (length=1)
2 =>
array (size=5)
'Statut' => string 'VALID' (length=5)
'Username' => string 'name' (length=12)
'Nom' => string 'firstname' (length=19)
'Email' => string '[email protected]' (length=14)
'Regularisation' => string 'N' (length=1)
3 =>
array (size=5)
'Statut' => string 'VALID' (length=5)
'Username' => string 'user2' (length=10)
'Nom' => string 'second_nae' (length=8)
'Email' => string '[email protected]' (length=27)
'Regularisation' => string 'N' (length=1)
は、今私は、私はすでにどこかに電子メールを見た場合に基づいて、いくつかのjQueryを使って、重複を削除するために管理します。ここで
はHTMLの一部です:
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th id="Statut">Statut</th>
<th id="Username">Username</th>
<th id="Nom">Nom</th>
<th id="Email">Email</th>
<th id="Regularisation">Regularisation</th>
</tr>
</thead>
<tbody>
<tr class="row">
<td class="statut">REFUSED</td>
<td class="username">name</td>
<td class="nom">firstname</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr><tr class="row">
<td class="statut">REFUSED</td>
<td class="username">name</td>
<td class="nom">firstname</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr><tr class="row">
<td class="statut">VALID</td>
<td class="username">name</td>
<td class="nom">firstname</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr><tr class="row">
<td class="statut">VALID</td>
<td class="username">user2</td>
<td class="nom">second_nae</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr>
</tbody>
</table>
そしてJS仕事をしている:JS後
var seen = {};
$('.mail').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).parent().remove();
else
seen[txt] = true;
});
、HTMLは次のようになります。
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th id="Statut">Statut</th>
<th id="Username">Username</th>
<th id="Nom">Nom</th>
<th id="Email">Email</th>
<th id="Regularisation">Regularisation</th>
</tr>
</thead>
<tbody>
<tr class="row">
<td class="statut">REFUSED</td>
<td class="username">name</td>
<td class="nom">firstname</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr><tr class="row">
<td class="statut">VALID</td>
<td class="username">user2</td>
<td class="nom">second_nae</td>
<td class="mail">[email protected]</td>
<td class="regularisation">N</td>
</tr>
</tbody>
</table>
問題を使用していますメールのみでは不十分です:
私は同じメールで2つのエントリーを持っていますが、異なるスタウトを持っている場合は、どちらか一方を保つ必要があります。
したがって、上記の例では、に削減されるだろう:
array (size=3)
0 =>
array (size=5)
'Statut' => string 'REFUSED' (length=5)
'Username' => string 'name' (length=4)
'Nom' => string 'firstname' (length=9)
'Email' => string '[email protected]' (length=14)
'Regularisation' => string 'N' (length=1)
1 =>
array (size=5)
'Statut' => string 'VALID' (length=5)
'Username' => string 'name' (length=12)
'Nom' => string 'firstname' (length=19)
'Email' => string '[email protected]' (length=14)
'Regularisation' => string 'N' (length=1)
2 =>
array (size=5)
'Statut' => string 'VALID' (length=5)
'Username' => string 'user2' (length=10)
'Nom' => string 'second_nae' (length=8)
'Email' => string '[email protected]' (length=27)
'Regularisation' => string 'N' (length=1)
私はそれがDOMナビゲーションをthroughtが、私はそれを正しく行うと、減らすために任意のPHPの方法があったかどうかを知りたいと思いませんでしたかなり確信しています配列を表示する前に。
を? – mplungjan
HTMLスニペットが追加されました – Nirnae
データがデータベースクエリから来ている場合は、レベルを1つ上げてください。重複したエントリを返さないようにクエリを変更し、それよりも高いレベルにすることもできます。それらの重複を最初から挿入しないようにします。 – apokryfos