Jump to content

[SOLVED] Duplicate Names


karenn1

Recommended Posts

I have a question that I'm not sure if it's possible in PHP. I have a table that looks as follows:

 

SQL Code:

 

$sql_prop = "SELECT Venue_Region, CONCAT(TMR_Name, ' ', TMR_Surname) AS Name,
  Venue_Name, SUM(Quantity) AS Quantity, ROUND(SUM(Value_Cost),0) AS Income
  FROM web_summary_info
  GROUP BY Venue_Region,(TMR_Name + ' ' + TMR_Surname), Venue_Name";
$result_prop = mysql_query($sql_prop);

 

PHP Code attached to a HTML table:

 

<?php
$i = 0;
while ($rs_prop = mysql_fetch_array($result_prop))	{
?>
<tr>
              <td style="padding-left:5px; padding-right:2px;" width="188" height="23" bgcolor="#E9EDF4" class="style35"><span class="style10">
                <?= $rs_prop["Name"]; ?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="style35" style="padding-left:5px; padding-right:2px;"><span class="style10">
                <?= $rs_prop["Venue_Name"]; ?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10">
                 
                <?= $rs_prop["Quantity"]; ?>
              </span></div></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10"> R
                <?= $rs_prop["Income"]; ?>
              </span></div></td>
              </tr>
            <?php $i++; }?>

 

This spits out a list of items as follows:

 

Bianca Bacon  Club 151  Rothmans Mint HL Lights    12   R 312      4   R 104.00  
Bianca Bacon  Club 151  Rothmans Rich HL Filter     44   R 1144    15  R 381.33

 

I want to remove the duplicate names but still keep the data. Like this:

 

Bianca Bacon  Club 151  Rothmans Mint HL Lights    12   R 312      4   R 104.00  
                         Rothmans Rich HL Filter     44   R 1144    15  R 381.33

 

Is this at all possible with PHP?

 

Thanks,

Karen

Link to comment
https://forums.phpfreaks.com/topic/74727-solved-duplicate-names/
Share on other sites

try this

<?php
$i = 0;
$tmpname = "";
while ($rs_prop = mysql_fetch_array($result_prop))	{
?>
<tr>
              <td style="padding-left:5px; padding-right:2px;" width="188" height="23" bgcolor="#E9EDF4" class="style35"><span class="style10">
<?php
if($rs_prop["Name"] != $tmpname)
{
$tmpname = $rs_prop["Name"];
echo $rs_prop["Name"]; 
}
?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="style35" style="padding-left:5px; padding-right:2px;"><span class="style10">
                <?= $rs_prop["Venue_Name"]; ?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10">
                 
                <?= $rs_prop["Quantity"]; ?>
              </span></div></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10"> R
                <?= $rs_prop["Income"]; ?>
              </span></div></td>
              </tr>
            <?php $i++; }?>

I would just keep track of the last name and venue and not display them if the current and last are the same. Also, why do you have the variable $i and incrementing it, you don't seem to be using it.

 

<?php
$prev = array('name' => '', 'venue_name' =>'');
$disp = array('name' => '', 'venue_name' => '');
while ($rs_prop = mysql_fetch_array($result_prop)) {
     foreach ($prev as $k => $v) {
           $disp[$k] = ($rs_prop[$k] == $v)?'':$rs_prop[$k];
           $prev[$k] = $rs_prop[$k];
     }
?>
<tr>
              <td style="padding-left:5px; padding-right:2px;" width="188" height="23" bgcolor="#E9EDF4" class="style35"><span class="style10">
                <?= $disp["Name"]; ?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="style35" style="padding-left:5px; padding-right:2px;"><span class="style10">
                <?= $disp["Venue_Name"]; ?>
              </span></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10">
                 
                <?= $rs_prop["Quantity"]; ?>
              </span></div></td>
              <td height="23" bgcolor="#E9EDF4" class="body4"><div align="right"><span class="style10"> R
                <?= $rs_prop["Income"]; ?>
              </span></div></td>
              </tr>
            <?php } ?>

 

Note: untested

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.