Reputation: 103
I had a loop which will give me array(array());From mysql join it gave 3 results, 2 result had same agency name so when i loop it display 2 agencies same name , so i want to check if same agency name , will output that agency name only one time.
<td><input type="checkbox" class="selected_news" value="<?=$agency['aid'];?>" name="news_id[]"></td>
<td><?=$agency['aid']?></td>
<td><?=$agency['aname']?></td>
<td><?=date('d/m/Y',$agency['aid'])?></td>
Upvotes: 0
Views: 34
Reputation: 1091
Please use below code
$agencyIDs = array();
foreach($agencies as $agency)
{
$agencyID = $agency['aid'];
if(!in_array($agencyID, $agencyIDs))
{
?>
<td><input type="checkbox" class="selected_news" value="<?= $agencyID; ?>" name="news_id[]"></td>
<td><?= $agencyID ?></td>
<td><?= $agency['aname'] ?></td>
<td><?= date('d/m/Y', $agency['aid']) ?></td>
<?php
$agencyIDs[] = $agencyID;
}
}
Upvotes: 1