karenn1 Posted October 25, 2007 Share Posted October 25, 2007 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 More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 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++; }?> Link to comment https://forums.phpfreaks.com/topic/74727-solved-duplicate-names/#findComment-377802 Share on other sites More sharing options...
kenrbnsn Posted October 25, 2007 Share Posted October 25, 2007 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 Link to comment https://forums.phpfreaks.com/topic/74727-solved-duplicate-names/#findComment-377805 Share on other sites More sharing options...
karenn1 Posted October 25, 2007 Author Share Posted October 25, 2007 MadTechie for president!!!!! Works like a charm!! Thank you sooo much!! Don't worry Ken. It's working like I need it to. Thanks! Link to comment https://forums.phpfreaks.com/topic/74727-solved-duplicate-names/#findComment-377808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.