0

so I'm making this deal website. On the index page of the deal website, there would be multiple deals listed and each deal has it's own end date.

Now, I'm using this jQuery script for the clock countdown.

<script>
$(function () {
    var austDay = new Date();
    austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
    $('#defaultCountdown').countdown({until: austDay});
    $('#year').text(austDay.getFullYear());
});
</script>

This is the database structure

Product ID           ProductName    End Date

(auto_increment)       (VARCHAR)      DATE

Now, I guess I would have to put the above jQuery script within a while loop (loop would go through the products, and display their details) to show the clock for each deal.

How would I pass a product id (for example let's say the productid is in the $productid variable) in jQuery, so that I can do a mysql query from there to get the end date..and then the clock displays the correct time for each deal.

Any suggestions are welcome.

NetStack
  • 206
  • 2
  • 3
  • 11
  • "How do I use AJAX with PHP" or "How do I pass PHP values to JavaSCript" or "How do I hand my JavaScript variables to PHP" is seriously asked here about once every 20 minutes. Please search and you will surely find an answer to your exact problem. – Two-Bit Alchemist Mar 19 '14 at 19:20
  • Googling "PHP and AJAX site:stackoverflow.com" gives 516,000 results. [Here is the first one](http://stackoverflow.com/questions/5298401/basic-php-and-ajax). – Two-Bit Alchemist Mar 19 '14 at 19:21

2 Answers2

0

If you are planing to use php as a server side language, I would suggest to add another two fields to the table "initial date" and "for how long the deal will be available" and then subtract the time. every time that the user enters to your web site you echo the result of the subtraction. You can manipulate this with jquery to display it as a countdown.

corr
  • 3
  • 2
0

You can use jquery ajax, so get correct date from php file via jquery ajax and set it into $('#defaultCountdown').countdown({until: austDay});. If you want get date peridly from php file so u can use javascript setTimeOut.

jquery ajax

settimeout