Jump to content

Number each entry.


strago

Recommended Posts

        $insertCount=0;
        foreach($results[1] as $curName)
        {
            if($insert){$insertCount++;}
        echo <<< END
$curName<BR>
END;

        }

 

Right now the results would show up as...

 

Bill

Fred

Jessica

James

John

 

How do you make them show up like...

 

1 Bill

2 Fred

3 Jessica

4 James

5 John

Link to comment
https://forums.phpfreaks.com/topic/210510-number-each-entry/
Share on other sites

Keeping to your code example:

 

       $insertCount=0;
        foreach($results[1] as $curName)
        {
            if($insert){$insertCount++;}
        echo <<< END
$insertCount $curName<BR>
END;

        }

 

Although, I would probably do this:

       $insertCount=0;
        foreach($results[1] as $curName)
        {
            if($insert){$insertCount++;}
            printf('%d %s<BR>', $insertCount, $curName);
        }

Link to comment
https://forums.phpfreaks.com/topic/210510-number-each-entry/#findComment-1098367
Share on other sites

What's with the $insert variable? Is that set, and is it true. Where are you pulling this variable from.

 

Try this:

$insertCount=0;
foreach($results[1] as $curName)
{
   $insertCount++;
   echo <<< END
     $insertCount $curName<BR>
END;
}

Link to comment
https://forums.phpfreaks.com/topic/210510-number-each-entry/#findComment-1098418
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.