Jump to content

Having to refresh the page to get correct value to appear.


perky416

Recommended Posts

Hi everyone,

 

Im using the code below to insert an item to auction, then calculate and display the time remaining until the auction ends. As soon as the confirm auction submit button is clicked, the item appears at auction straight away, however the time remaining is 0s, i have to refresh the page in order to get the end time to appear correctly.

 

Does anybody know why this is happening and what i can do to get the correct end time to appear straight away?

 

Thanks

 

<?php

if ($_POST['confirm_auction'])
{
foreach ($_POST['checkbox'] as $checked)
{
	$add_auction_query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer' AND item='$checked'");
	while ($row = mysql_fetch_assoc($add_auction_query))
	{
		$starting_bid = $row['offer'];
		$current_bid = $starting_bid;
		$start_date = date("Y-m-d H:i:s");
		$end_date = date("Y-m-d H:i:s", strtotime("+1 week"));
		mysql_query("INSERT INTO auctions VALUES ('','$checked','$username','$starting_bid','$current_bid','$buyer','1','At Auction','$start_date','$end_date')");
		mysql_query("INSERT INTO bids VALUES('','$checked','$username','$buyer','$starting_bid','$start_date')");
		mysql_query("UPDATE offers SET seller_status='At Auction',buyer_status='At Auction' WHERE item='$checked'");
	}
echo "Offer(s) Sent to Auction";
}
}

$x = 0;
while ($auction_row = mysql_fetch_assoc($auction_query))
{
$then = strtotime($auction_row['end_date']); 
$now = time();
$diff = $then - $now; 

$weeks = floor($diff / (60*60*24*7)); 
$diff = $diff - ($weeks * (60*60*24*7)); 

$days = floor($diff / (60*60*24)); 
$diff = $diff - ($days * (60*60*24)); 

$hours = floor($diff / (60*60)); 
$diff = $diff - ($hours * (60*60)); 

$minutes = floor($diff / 60); 
$diff = $diff - ($minutes * 60); 

$seconds = $diff;
?>
<html>
<table>
    <tr>
        <td>
		<?php 
            if ($week > 0) {echo  $weeks . "w ";} 
            if ($days > 0) { echo $days . "d ";} 
            if ($hours > 0) {echo $hours . "h ";} 
            if ($minutes > 0) { echo $minutes . "m ";}   
            if ($hours < 1) {echo $seconds . "s";}
            ?>
        </td>
    </tr>
</table>
</html>
<?php
$x++;
}
?>

Archived

This topic is now archived and is closed to further replies.

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