Coneecausecor
New Member
I'm running into problems trying to properly format my data.First of all, my PHP code looks like this (See JSFiddle for demo):\[code\]$result_rules = $db->query("SELECT rules.source_id, rules.destination_id, dest.project AS dest_project, src.project AS src_project, src.pk_id AS src_id, excep.project AS excep_project, excep.feature AS excep_feature, excep.milestone AS excep_milestone FROM dbo.FFC_Rules rules INNER JOIN dbo.Destination dest ON dest.pk_id=rules.destination_id LEFT JOIN dbo.Source src ON src.pk_id=rules.source_id LEFT JOIN dbo.Exceptions excep ON src.pk_id=excep.source_id ORDER BY dest.project ASC");$last_src = http://stackoverflow.com/questions/15510670/false;$last_dest = false;while($row = sqlsrv_fetch_array($result_rules)){ if ($row['dest_project'] !== $last_dest) { if ($last_dest !== false) echo "</div>"; $last_dest = $row['dest_project']; echo "<div class='projectscontainer'>"; echo "<div id='arrow' class='arrow-right'></div>"; echo "<span class='item destproject unselectable' title='ID: $row[destination_id]'>$row[dest_project]</span>"; echo "<br>"; } echo "<div class='srcprojects'>"; if (is_null($row['src_id'])) { echo " Source ID for Destination ID $row[destination_id] is NULL"; } else { if($row['src_project'] !== $last_src) { $last_src = http://stackoverflow.com/questions/15510670/$row['src_project']; echo "<span class='item srcproject' title='ID: $row[src_id]'>$row[src_project]</span>"; if (!is_null($row['excep_feature'])) echo"<div id='arrow' class='arrow-right'></div><span class='item srcproject exception' title='Feature'>$row[excep_feature]</span>"; if (!is_null($row['excep_milestone'])) echo"<div id='arrow' class='arrow-right'></div><span class='item srcproject exception' title='Milestone'>$row[excep_milestone]</span>"; echo "<br>"; } } echo "</div>";//end srcprojects}echo "</div>";//end projectscontainer\[/code\]In my query, I ordered by Destination project, and in my PHP code I check if the current dest is the same as the last. If so, I don't display the name. I want to do the same for the Source project, but since the query is ordered by Destination project, the repeats occur in different places and are not caught by my PHP code.How can I accomplish this without having to grab all 40,000+ rows returned by the query again?