如何在2次运行后暂停循环,在两次之间插入代码,然后继续循环停止?

I currently have a loop of items being shown on a page.

I would like to run the loop twice (output 2 results/items), and THEN insert a banner ONCE right after the 2nd result, and THEN let loop continue from where it left off.

An illustration below:

{--- START OF LOOP ---}

ITEM 1 | ITEM 2
{ BANNER HERE }
ITEM 3 | ITEM 4
ITEM 5 | ITEM 6
ITEM 7 | ITEM 8

{--- END OF LOOP ---}
<- prev | next ->

The items are inside a while loop:

$sql = mysql_query("SELECT id, img, description, keyword, category FROM images WHERE connect = 1 ORDER BY id DESC LIMIT $from , $perPage");

while($result = mysql_fetch_object($sql)) {
LOOP OF ITEMS HERE }

I've only ever found "do" / "while" methods, which isn't really what I'm looking for. If anyone could help, thank you for your time & assistance.

$i=1;
while($result = mysql_fetch_object($sql)) {
    //print item
    if($i==2) { 
        //print banner
    }
    $i++;
}

if you want it to print every 2 items the yu can use

if($i % 2 == 0)

You could also just print the first item outside the loop, then print the banner, then iterate over the remaining items:

$result = mysql_fetch_object($sql)
// print item
// print banner
while($result = mysql_fetch_object($sql)) {
    // print item
}

Neil's solution is more general, but this may be simpler. Note that your $sql resource has an internal pointer that doesn't reset automatically, so if you call it once outside the while loop, the while loop will start with the second item. In this case that's what you want.