Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:36+00:00 2026-05-23T13:11:36+00:00

I have a PHP loop like this <?php foreach ($products as $product) { ?>

  • 0

I have a PHP loop like this <?php foreach ($products as $product) { ?> now inside this loop I will be creating some div. the number of divs created depends on number of products. Also, I have a javascript function that creates a countdown.

Now I am trying to create a unique countdown in every div that gets created. .ie unique countdown for every product. here is the code that generates the coundown

$(function(){$('.counter').countdown({startTime:"<?php echo $product['time']; ?>" });}); 

and this is what I have inside the php loop that creates the divs

<div class= 'counter' ></div>

now what this gives me is the same counter in all the divs. I’m new to all this, I haven’t slept in hours trying to learn and figure out what I’m doing wrong.

EDIT:

So I still have not get what I want.
$(‘.counter’).each(function() { $(this).countdown(….
produce the same counter for all the divs. and for some reason I get syntax error when I try to use
$(‘#product-‘).countdown(…
in order to create a unique selector.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:11:36+00:00Added an answer on May 23, 2026 at 1:11 pm

    This won’t work as the selector .counter will find all elements with the class name counter.

    Assuming that time varies for every product and that you have a unique identifier for every product, you could solve this by assigning an unique ID to every div-element, and use this as a means to trigger the countdown process:

    <div id="product-<?php echo $product['id']; ?>" class="counter"></div>
    

    And the Javascript-code:

    $('#product-<?php echo $product['id']; ?>').countdown({startTime: '...'});
    

    I’d suggest a design pattern though where you don’t have to generate javascript code like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok so i have this array and i need to loop through <?php foreach($classes
We have a PHP project that we would like to version control. Right now
Hello I currently have this PHP Script <?php if($purchase_dates != FALSE){?> <?php foreach($purchase_dates as
If I have a foreach construct, like this one: foreach ($items as $item) {
In PHP, I have an associative array like this $a = array('who' => 'one',
I have a table that's generated by a normal PHP loop. What I want
I have the below code in a page. <?php if($this->getMode()!='grid'): ?> <?php $_iterator =
I am not strong on my PHP knowledge, but I have never seen this
I have an event calendar with start and end date like this: 16.08.2010 12:00:00
I need some help with re-working the logic on this php code. What I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.