0

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>

0

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.