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
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
Share on other sites

Yah, I had tried the

 

$insertCount $curName<BR>

 

but it only spit it out as...

 

1 Bill

1 Fred

1 Jessica

1 James

1 John

 

Then

 

printf('%d %s<BR>', $insertCount, $curName);

 

did the same thing. For some reason it's not actually counting.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.