• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

Text Injection In Display

Ok, so I'm given a list of parts like so:
PartID    CatID    PartName
0             1           Part 1
1             2           Part 2
2             1           Part 3
3             3           Part 4
4             2           Part 5
5             2           Part 6

I'm using PHP to pull.   How can I inject a blurb of text at each change in CatID, without having to run multiple loops?

So on page:
"BLURB OF TEXT"
Part 1
Part 3
"BLURB OF TEXT"
Part 2
Part 5
Part 6
"BLURB OF TEXT"
Part 4

while($row = sqlsrv_fetch_array($qry, SQLSRV_FETCH_ASSOC)) {
    echo $row["PartName"]
}

Open in new window

0
kevp75
Asked:
kevp75
1 Solution
 
GaryCommented:
Just check if the if the CatID is the same as the previous in the loop

$tempID=0;
while($row = sqlsrv_fetch_array($qry, SQLSRV_FETCH_ASSOC)) {
    if ($tempID!=$row['CatID']){echo "blurb";}

    echo $row["PartName"]
    $tempID=$row['CatID'];
}
0
 
kevp75Author Commented:
actually got it figured out prior to checking the q... but yes, that's what I did.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now