title: How to loop data for the same id without showing the id repeatedly using foreach?
body: <p><br/>I'm trying to display rental amount and days relevant to car id. I'm first displaying car names for  car Make  clicked by user.</p>
  
  <p>When it displays car names,it must display number of rental days and rental amount as well.
  But since I store days and amount for a car id in the backend three times, it also loop three times in front end.</p>
  
  <p>To make it clearer:</p>
  
  <p>// in the back end,
  I stored the days and amount for a car multiple times instead of one time<br/>
  <strong>carName</strong> <strong>days</strong> <strong>amount</strong><br/>
  carname1      1        50<br/>
  carname1      7        650<br/>
  carname1      30       2000<br/></p>
  
  <p>And I'm calling the carName,gallery,rental_days and rental_amount like this:</p>
  
  <pre><code>     if(isset($q))
  {
  mysql_select_db($database);
  /*$query_showmake="SELECT carName FROM car_name WHERE carMake_id='$q'";*/
  $query_showmake="SELECT rental.rental_days,rental.rental_amount,rental.carName_id,car_name.carName_id,car_name.carName,car_name.carMake_id,gallery,gallery_id,gallery.gallery,gallery.carName_id,car_make.carMake_id  FROM rental,car_name,gallery,car_make WHERE car_name.carName_id=gallery.carName_id AND car_name.carMake_id='$q' AND car_name.carMake_id=car_make.carMake_id AND rental.carName_id=car_name.carName_id ORDER BY rental_days ASC";
  
  $result_showmake=mysql_query($query_showmake)or die(mysql_error());
  while($row_showmake=mysql_fetch_array($result_showmake))
  {
  $carMake_show=$row_showmake['carName'];
  $carmake[$row['carName_id']][]=$row_showmake;
  /* echo $carMake_show.'&lt;br/&gt;';*/
  
  
  }
  ?&gt;
  &lt;table border="0" style="border-collapse:collapse"&gt;
  &lt;?php
  foreach($carmake as $make=&gt;$name)
  {
  
  foreach($name as $n)
  {
  echo "&lt;tr&gt;";
  echo "&lt;td class='carname'&gt;".$n{'carName'}.'&lt;/td&gt;&lt;td rowspan="2" valign="top" class="cardetail"&gt;Car Details&lt;/td&gt;&lt;/tr&gt;';
  /*echo $n{'carMake_id'}.'&lt;br/&gt;';
  echo $n{'gallery'}.'&lt;br/&gt;';*/
  echo"&lt;tr&gt;&lt;td class='img'&gt;&lt;img src='management/uploads/{$n['carMake_id']}/{$n['gallery']}' width='400' height='200'&gt;";
  echo "&lt;/td&gt;&lt;/tr&gt;";
  echo"&lt;tr&gt;&lt;td colspan='2' class='days'&gt;Days : ";
  $days[]=$n['rental_days'];
  foreach($days as $day)
  {
  echo $day."&amp;nbsp;";
  }
  echo "&lt;/td&gt;&lt;/tr&gt;";
  
  echo"&lt;tr&gt;&lt;td colspan='2' class='days'&gt;Amount : ";
  $amount[]=$n['rental_amount'];
  foreach($amount as $amt)
  {
  echo "RM ".$amt."&amp;nbsp;";
  }
  echo "&lt;/td&gt;&lt;/tr&gt;";
  echo"&lt;tr&gt;&lt;td height='50' colspan='2'&gt;&lt;/td&gt;&lt;/tr&gt;";
  
  }
  }?&gt;
  &lt;/table&gt;
  &lt;?php
  }
  </code></pre>
  
  <p>And it displays the result like this:</p>
  
  <p>carName 1<br/>
  image 1<br/>
  days 1<br/>
  amount 50<br/><br/></p>
  
  <p>carName 1<br/>
  image 1<br/>
  days 7<br/>
  amount 650<br/><br/></p>
  
  <p>carName 1<br/>
  image 1<br/>
  days 30<br/>
  amount 2000<br/><br/></p>
  
  <p>AND I want to display like:</p>
  
  <p>carname 1<br/>
  days:1&nbsp;&nbsp;  7&nbsp;&nbsp;    30<br/>
  amt: 50 &nbsp;650&nbsp;  2000<br/></p>