Text Injection In Display

Posted on 2012-09-06
Last Modified: 2012-09-06
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:
Part 1
Part 3
Part 2
Part 5
Part 6
Part 4

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

Open in new window

Question by:kevp75
    LVL 58

    Accepted Solution

    Just check if the if the CatID is the same as the previous in the loop

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

        echo $row["PartName"]
    LVL 25

    Author Closing Comment

    actually got it figured out prior to checking the q... but yes, that's what I did.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now