My PHP is probably just marginally if at all better than your jQuery. I have no experience with databases.
If <?php the_permalink() ?> is different for each countdown (looks like it is from the served source code of ending.php), I can see one problem right away. Even with starting.php as is, as a standalone page, if there are more than one countdowns on it, the last:
PHP Code:
function liftOff() {
window.location.href="<?php the_permalink() ?>";
}
will overwrite all the others, so any/all countdowns, once they expire, would go to the last one's 'the_permalink()'. To fix that, you would either need to establish javascript scope for the onExpiry function, or come up with unique names (as you have for the divisions' ids) for each liftOff function.
I'd go with javascript scope, change:
PHP Code:
<script type="text/javascript">
$(function () {
$("#ks<?php echo $i;?>").countdown({until: new Date("<?php echo $start_date;?>"), onExpiry: liftOff})
});
function liftOff() {
window.location.href="<?php the_permalink() ?>";
}
</script>
to:
PHP Code:
<script type="text/javascript">
$(function () {
$("#ks<?php echo $i;?>").countdown({until: new Date("<?php echo $start_date;?>"), onExpiry: function(){
window.location.href="<?php the_permalink() ?>";
}})
});
</script>
That still doesn't get us much closer to using the page with AJAX though.
For that, do as I suggest. If you want starting.php to still work on its own, you can leave it (with the one change I suggested above) alone. Even if you don't want it to work on its own, it would still need that portion of the PHP code that's required to generate the markup. Either way, put this:
PHP Code:
<?php global $wpdb,$ksdb,$root_dir;
$now=date('Y-m-d H:i:s');
$wpdb->show_errors();
$ks_view = $wpdb->get_results("SELECT * FROM $ksdb WHERE (start_date>'$now' && exp_date>'$now') ORDER BY start_date ASC");
$i=0;
?>
<!-- #Countdown Timer starts -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo $root_dir.'/wp-content/plugins/KiasuSales/js/jquery.countdown.js';?>"></script>
<!-- #Countdown Timer End-->
<style type="text/css">
@import "<?php echo $root_dir.'/wp-content/plugins/KiasuSales/css/jquery.countdown.css';?>";
<?php for ($rows=0;$rows<count($ks_view);$rows++){?>
#ks<?php echo $rows;?> { width: 240px; height: 45px; }
<?php }?>
</style>
on the top page (view-sales). And on that same page, where you have:
Code:
<script type="text/javascript">
var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()
</script>
do:
PHP Code:
<script type="text/javascript">
var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()
countries.onajaxpageload=function(pageurl){
if (pageurl.indexOf("starting.php")!== -1){
<?php foreach($ks_view as $ks) {
$start_date=preg_replace('/-/','/',$ks->start_date);
?>
$("#ks<?php echo $i;?>").countdown({
until: new Date("<?php echo $start_date;?>"),
onExpiry: function(){
$('#countrydivcontainer').load('<?php the_permalink() ?>', function(){/* optional callback code */});
}
});
<?php $i++; }?>
}
}
</script>
Note: I've gone over this pretty thoroughly but have no way of testing it. Much of it relies upon the fact that your current code appears to work. It doesn't take into account things for which you might not have tested your current code for. And it may be subject to typos and/or misunderstanding on my part. You can backup what you have and try it, if there are PHP errors, those should be reported in some way, hopefully one that will be easy to understand and correct. If there are javascript problems, give me a link to the new page and I'll see what I can find out.
Bookmarks