数据存在我的数据库中,如下所示......
COLUMNNAME surveyor_name -varchar
bookingdate - varchar
receipt_no - varchar
surveyor bookingdate receipt_no
raj 19-03-2015 55
raj 19-03-2015 55
raj 19-03-2015 55
raj 19-03-2015 55
raj 19-03-2015 55
raj 19-03-2015 55
raj 19-03-2015 56
raj 19-03-2015 56
raj 19-03-2015 56
raj 19-03-2015 56
raj 19-03-2015 56
raj 19-03-2015 56
sudnyesh 20-03-2015 700
sudnyesh 20-03-2015 700
sudnyesh 20-03-2015 700
sudnyesh 20-03-2015 700
sudnyesh 20-03-2015 700
sudnyesh 20-03-2015 700
angel 24-03-2015 702
angel 24-03-2015 702
angel 24-03-2015 702
angel 24-03-2015 702
angel 24-03-2015 702
angel 24-03-2015 702
预期输出
surveyor name 19-03-2015 20-03-2015 24-03-2015
angel 1
raj 2
sudnyesh 1
但我的代码显示输出如下......
surveyor name 19-03-2015 20-03-2015 24-03-2015
angel 1 1
raj 2 2
sudnyesh 1 1
任何人都可以帮我显示正确的输出。
下面是我的代码。
FOR EX - 在我的预期输出中....
raj在19-03-2015创建了2张收据55,56,因此我们在19-03-2015以下的raj前面显示总共2张
sudnyesh在20-03-2015创建了1张收据700,因此我们在20-03-2015以下的sudnyesh前面显示总共1张......
请帮我实现这个目标..
<?php $book = $database->getRows("SELECT DISTINCT bookingdate FROM receipt_entry"); ?>
<?php $data = $database->getRows("select surveyor_name, count(DISTINCT receipt_no) As total,bookingdate from receipt_entry group by surveyor_name,bookingdate"); ?>
<table border="1px solid #666" style="text-align:center;" cellpadding='0' cellspacing='0'>
<thead>
<tr>
<th>Surveyor Name</th>
<?php foreach($book as $date):?>
<?php $dates[] = $date['bookingdate'];?>
<th><?php echo $date['bookingdate'];?></th>
<?php endforeach;?>
</tr>
</thead>
<tbody>
<?php $j = 0;?>
<?php foreach($data as $key => $value):?>
<?php $names[] = $value['surveyor_name'];?>
<?php $uniValues = array_count_values($names);?>
<?php if($uniValues[$value['surveyor_name']] == 1):?>
<tr>
<td>
<?php echo $value['surveyor_name'];?>
</td>
<?php $i = 0;?>
<?php foreach($book as $date):?>
<td align="center">
<?php if($names[$i] == $data[$j]['surveyor_name']):?>
<?php echo $data[$j]['total'];?>
<?php else:?>
<?php foreach($data as $dat):?>
<?php if($dat['surveyor_name'] == $names[$j] && $dates[$i] == $dat['bookingdate']):?>
<?php echo $dat['total'];?>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
</td>
<?php ++$i;?>
<?php endforeach;?>
</tr>
<?php endif;?>
<?php ++$j;?>
<?php endforeach;?>
</tbody>
</table>