Welcome Guest, Not a member yet? Register   Sign In
Removing dulicates during echo
#1

[eluser]davehedgehog[/eluser]
hi basically what im trying todo is remover the venue where it repeats its self during and echo. at the moment it work but for only the next entry because or the for each. heres the code~
Code:
<?php $prevenue=false;?><?php $pretitle=false;?>
<?php if ($education): ?>
<?php foreach($education as $ed): ?>

<table class="table" >
&lt;?php if($prevenue == $ed['place']){
$ed['place'] = '';
}else{?&gt;
<tr><td>Venue of  study:<td>&lt;?php echo $ed['place']; ?&gt;</tr>
&lt;?php } ?&gt;
<tr><td>from:<td>&lt;?php echo $ed['datefrom']; ?&gt;<td>To:<td>&lt;?php echo $ed['dateto']; ?&gt;</tr>
<tr><td>Title: <td>&lt;?php echo $ed['title']?&gt;</tr>
<tr><td>Module: <td>&lt;?php echo $ed['module']?&gt;</tr>
<tr><td>Description: <td>&lt;?php echo $ed['description']?&gt;</tr>
&lt;?php $prevenue = $ed['place'];?&gt;
</table>&lt;?php endforeach;?&gt;&lt;?php else: ?&gt;

<br></br>
<p>
    There are no education for this portfolio.
</p>&lt;?php endif;?&gt;

I want to change this to a while so that for every echo if the venue is there then dont repeat, but when I try while it falls over, any help?
#2

[eluser]MonkeyZeus[/eluser]
I assume you are retrieving this data from a DB so I would personally try and modify the query to only pull the results that you need.

However, for your situation I would implement something like this:
Code:
$unique_venues = array();

echo '<table>';
foreach($education as $ed){
   if(!array_key_exists($ed['place'], $unique_venues)){
      $unique_venues[$ed['place']] = '';
      //echo your <tr> stuff
   }
}
echo '</table>';

Good Luck!
#3

[eluser]davehedgehog[/eluser]
awesome cheers pal =)




Theme © iAndrew 2016 - Forum software by © MyBB