Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.