tonomud Posted January 1, 2014 Share Posted January 1, 2014 I have a MySQL query that is returning the results that I need correctly. However, I want to clean up the output a bit for my specific use case. Specifically, I'd like to remove a column from the output so that it only appears the first time it's pulled from the database. Here's a quick example of the type of output I'm getting: Campaign A - asset 1Campaign A - asset 2Campaign A - asset 3Campaign B - asset 1Campaign B - asset 3Campaign C - asset 2Campaign D - asset 1Campaign D - asset 2etc This is what I'd like instead: Campaign Aasset 1asset 2asset 3Campaign Basset 1asset 3Campaign Casset 2Campaign Dasset 1asset 2 So, basically, I just want to see the "Campaign A" title once, even though it's part of the record of workshops. Here's the php code that I'm working with (in this case, "campaigntitle" is the column I only want to see once per group. "assettitle" would be shown in every row returned by the query) : <?php do { ?><tr><td><a href="detail-nd.php?recordID=<?php echo $row_assetslist['assetid']; ?>"> Details</a> <a href="assetupdate-nd.php?recordID=<?php echo $row_assetslist['assetid']; ?>">edit</a> delete</td><td><?php echo $row_campaignassetjoin['campaigntitle']; ?></td><td><?php echo $row_campaignassetjoin['assettitle']; ?></td><td><?php echo $row_campaignassetjoin['assettype']; ?></td></tr><?php } while ($row_campaignassetjoin = mysql_fetch_assoc($campaignassetjoin)); ?> here's the pertinent mysql query in the document header: mysql_select_db($database_campaignarchive, $campaignarchive);$query_campaignassetjoin = "SELECT assets.*, campaign.* FROM campaign JOIN assets ON assets.campaignid=campaign.campaignid ORDER BY campaign.campaignid DESC";$campaignassetjoin = mysql_query($query_campaignassetjoin, $campaignarchive) or die(mysql_error());$row_campaignassetjoin = mysql_fetch_assoc($campaignassetjoin);$totalRows_campaignassetjoin = mysql_num_rows($campaignassetjoin); Quote Link to comment https://forums.phpfreaks.com/topic/285026-how-to-format-1st-row-in-mysql-output-differently-from-all-following-rows-in-php/ Share on other sites More sharing options...
Barand Posted January 1, 2014 Share Posted January 1, 2014 Check for a change in colA and only output when it changes pseudocode: currentCampaign = '' while fetch next row if campaign != currentCampaign print campaign currentCampaign = campaign endif print asset endwhile Quote Link to comment https://forums.phpfreaks.com/topic/285026-how-to-format-1st-row-in-mysql-output-differently-from-all-following-rows-in-php/#findComment-1463537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.