Jump to content

Counter Quesiton


soma56

Recommended Posts

Does anyone have an example code of a counter? For example: If I had an array echoing results I'd like to have a counter that remains in the same spot - the value would change as results were echoed. I can't seem to find any samples online.

 

 

Link to comment
Share on other sites

This would display 12345678910. What you would be looking for is:

 

echo count( $array ) . '';

 

Or:

 

$counter = 0;

foreach ( $array as $element )
{
    $counter++;
}

echo $counter;

 

You're welcome.

Link to comment
Share on other sites

Again, I appreciate it Bob but it's not what I'm looking for. I'm trying to figure out how to have a counter that is static, doesn't move or is otherwise always in the same place. I understand the concept of adding++ 'while' something is 'not true' however what I don't get is how you can echo a variable to the same spot as a means of letting know in real time.

Link to comment
Share on other sites

You should go through W3Schools tutorials: http://www.w3schools.com/

 

<body>
<div id='counter'></div>
</body>

<script type="text/javascript">

theArray = new Array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' );

for ( counter in theArray )
{
document.getElementById( 'counter' ).innerHTML = theArray[counter];
}

</script>

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.