Aşağıdaki gibi bir tablom var.
id | name | packet_1
----------------------------
1 | John | ppp
2 | Maria | pbt
3 | Jay | pbt
4 | Jay | ppp
5 | John | ptt
6 | Jay | ppp
7 | Maria | pxx
Fakat ben bunu sitede gösterirken şu şekilde göstermem gerekiyor:
name | ppp | pbt | ptt | pxx
John | 1 | 0 | 1 | 0
Maria | 0 | 1 | 0 | 1
Jay | 2 | 1 | 0 | 0
Bunu nasıl yapabilirim.
Eğer packet_1 değerin sabit ise bu şekilde de yapabilirsin.
Örnek olmak açısından bende ekleyim.
<?php
echo '<table width="500" border="1">
<tr height="24">
<td width="60%">name</td>
<td width="10%">ppp</td>
<td width="10%">pbt</td>
<td width="10%">ptt</td>
<td width="10%">pxx</td>
</tr>';
$verileri_cekelim=mysql_query("select id, name, packet_1 from tabloadi order by name asc");
while($goster=mysql_fetch_array($verileri_cekelim)){
$id=$goster["id"];
$name=$goster["name"];
$packet=$goster["packet_1"];
$ppp=mysql_num_rows(mysql_query("select id from tabloadi where packet_1='ppp'"));
$pbt=mysql_num_rows(mysql_query("select id from tabloadi where packet_1='pbt'"));
$ptt=mysql_num_rows(mysql_query("select id from tabloadi where packet_1='ptt'"));
$pxx=mysql_num_rows(mysql_query("select id from tabloadi where packet_1='pxx'"));
echo '<tr height="24">
<td width="60%">'.$name.'</td>
<td width="10%">'.$ppp.'</td>
<td width="10%">'.$pbt.'</td>
<td width="10%">'.$ptt.'</td>
<td width="10%">'.$pxx.'</td>
</tr>';
}
echo '</table>';
?>