hi all.
i hope someone could help me.
i'm trying to build a bidding site using ajax, and php.
what i want to do is that: when the bid time is over 5 minutes, the "div" i've placed will refresh every 10 seconds, and when its under it will refres every 5 seconds.
i've tried everything i know but i still cant make it work.
the best i got is that i have to refresh the whole site using the F5 button and then it changed, but i want it to change automaticly.
this is my main html/php code:

<?php 
session_start(); 
include("database2.php");
include("login.php");
$_SESSION['timeout']=1;


?>
<html>
<head>

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
var i=false;

function check()
{
	t=null;
	clearTimeout(t);
	<?php
	if($_SESSION['timeout']==1)
	{
	?>
	ajaxFunction2();
	t=setTimeout("check()",10000);
	<?php 
	} 
	else
	if($_SESSION['timeout2']==2)
	{
	?>
	ajaxFunction2();
	t=setTimeout("check()",5000);
	<?php 
	}
	
	?>

}

function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajax2.php", true);
	ajaxRequest.send(null);
}


function ajaxFunction2(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			//ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajax3.php", true);
	ajaxRequest.send(null);
	//t=null;

	}	


//-->
</script>
</head>
<body onload='check();'>
<?php 
 
if($logged_in){
	if($_SESSION['username']==1)
	{
		header('location: http://localhost/final/admin.php');
    
	} 
	 echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
?>

<?php 	

$id=$_GET['id'];
$data = mysql_query("SELECT * FROM pubbid WHERE id='$id'") or die(mysql_error());
$info = mysql_fetch_array( $data );


Print "<table border=1 align=center>";
Print "<tr><td colspan=7 align=center>".$info['name'] . "</td></tr> ";

Print "<tr>";
Print "<td width=40px colspan=7 align=center> <img src=".$info['pic'] . " width=300px height=300px></td>";
Print "</tr>";
Print "<tr><td>Name:</td><td>Type: </td><td>Start Price:</td><td>Bid Jump: </td><td>Market Value:</td><td>Delivery Time: </td><td>Delivery Type: </td></tr>";
Print "<td width=40px >".$info['name'] . "</td> ";
Print "<td width=40px >".$info['objects'] . "</td> ";
Print "<td width=40px >".$info['startprice'] . "</td> ";
Print "<td width=40px >".$info['jump'] . "</td> ";
Print "<td width=40px >".$info['market'] . "</td> ";
Print "<td width=40px >".$info['time'] . "</td> ";
Print "<td width=40px >".$info['get'] . "</td> ";
Print "</td></tr>";
Print "</table>";

$_SESSION['id']=$info['id'];
$_SESSION['ishit']=1;
//$_SESSION['isdo2']=1;

?>

<div id='ajaxDiv'>Current Higher Bidder: <?php echo $info['winner']; ?> </div>

<form name='myForm'>
<table>
<tr><td><input type='button' onclick='ajaxFunction();' value='BID'/></td></tr>
</table>
</form>
        <?php 
}


else{
	displayLogin();
   //echo 'Not logged in.';
}
?>

</body>
</html>

and this is my ajax php code:

<?php
session_start(); 
include("database2.php");


$id=$_SESSION['id'];
$data = mysql_query("SELECT * FROM pubbid WHERE id='$id'") or die(mysql_error());
$info = mysql_fetch_array( $data );
date_default_timezone_set('GMT');
$k=getdate();
 $target = mktime($info['hours']-2, $info['minutes'], 0, $info['month'], $info['day'], $info['year']) ;

$today = time () ;

$difference =($target-$today) ;
$days=(int) ($difference/86400) ;
$hours =(int) ($difference/3600) ;
$minutes = floor((((($difference%31556926)%2629744)%86400)%3600)/60); // remainder of hours into minutes - 60 seconds in a minute
        $seconds = floor((((($difference%31556926)%2629744)%86400)%3600)%60);
if($seconds>-1)
{
	if($minutes>3)
	{
		echo "Current Bid: ".$info['current']."<BR>Current Winner: ".$info['winner']."<BR>Time Untill Bid End: $days days $hours hours $minutes minutes $seconds seconds";

	}
	else
	{
		$_SESSION['timeout']=2;
		echo "Current Bid: ".$info['current']."<BR>Current Winner: ".$info['winner']."<BR>Time Untill Bid End: $days days $hours hours $minutes minutes $seconds seconds";
		
	}
}
else
{
	$_SESSION['ishit']=0;
	$data = mysql_query("DELETE FROM pubbid WHERE id='$info[id]'") or die(mysql_error());
	$q = "INSERT INTO pubbid VALUES ('$info[username]','$info[name]','$info[id]','$info[objects]','$info[type1]','$info[startprice]','$info[jump]','$info[minprice]','$info[market]','$info[time]','$info[get]','$info[pic]','close','$info[winner]','$info[current]','$info[hours]','$info[minutes]','0','$info[day]','$info[month]','$info[year]')";
	$result=mysql_query($q,$conn);
	if($info['winner']==$_SESSION['username'])
	{echo "BID IS CLOSED!<br>Winner: ".$info['winner']."<br>Congratulation!";}
	else
	{
	echo "BID IS CLOSED!<br> You Did Not Win... Try Again!";
	}	
}
?>

well, i've managed to work it out.
this is how i did it so if any 1 in the future get stuck he could see:

html+javascript file:

<?php 
session_start(); 
include("database2.php");
include("login.php");


?>
<html>
<head>

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
var i=false;

function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajax2.php", true);
	ajaxRequest.send(null);
}


function ajaxFunction2(f){
	var k=document.getElementById('1');
	var p=k.value;
	p=p*1;
	//alert(p);
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajax3.php", true);
	ajaxRequest.send(null);
	//var k=f.check.value*1;
	if(p==1)
	{
	t=setTimeout("ajaxFunction2(this.form)",10000);
	}
	if(p==2)
	{
		t=setTimeout("ajaxFunction2(this.form)",3000);
	}
	
}

//-->
</script>
</head>
<body onload='ajaxFunction2(this.form);'>
<?php 
 
if($logged_in){
	if($_SESSION['username']==1)
	{
		header('location: http://localhost/final/admin.php');
    
	} 
	 echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
?>
<table bgcolor="#669966" border="1">
<tr>
<td height="300px" width="1200px" align="center" colspan="12">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1080" height="300" id="menu" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="menu.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#669966" /><embed src="menu.swf" quality="high" bgcolor="#669966" width="1080" height="300" name="menu" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</td>
</tr>
</table>
<?php 	

$id=$_GET['id'];
$data = mysql_query("SELECT * FROM pubbid WHERE id='$id'") or die(mysql_error());
$info = mysql_fetch_array( $data );

Print "<table border=1 align=center>";
Print "<tr><td colspan=7 align=center>".$info['name'] . "</td></tr> ";

Print "<tr>";
Print "<td width=40px colspan=7 align=center> <img src=".$info['pic'] . " width=300px height=300px></td>";
Print "</tr>";
Print "<tr><td>Name:</td><td>Type: </td><td>Start Price:</td><td>Bid Jump: </td><td>Market Value:</td><td>Delivery Time: </td><td>Delivery Type: </td></tr>";
Print "<td width=40px >".$info['name'] . "</td> ";
Print "<td width=40px >".$info['objects'] . "</td> ";
Print "<td width=40px >".$info['startprice'] . "</td> ";
Print "<td width=40px >".$info['jump'] . "</td> ";
Print "<td width=40px >".$info['market'] . "</td> ";
Print "<td width=40px >".$info['time'] . "</td> ";
Print "<td width=40px >".$info['get'] . "</td> ";
Print "</td></tr>";
Print "</table>";

$_SESSION['id']=$info['id'];
$_SESSION['ishit']=1;
//$_SESSION['isdo2']=1;

?>



<form name='myForm'>
<div id='ajaxDiv'><input type="hidden" id="1" value="1" ></div> 

<table>
<tr><td><input type='button' onclick='ajaxFunction();' name='bid' value='BID'/></td></tr>
</table>
</form>
        <?php 
}


else{
	displayLogin();
   //echo 'Not logged in.';
}
?>

</body>
</html>

ajax code

<?php
session_start(); 
include("database2.php");


$id=$_SESSION['id'];
$data = mysql_query("SELECT * FROM pubbid WHERE id='$id'") or die(mysql_error());
$info = mysql_fetch_array( $data );
date_default_timezone_set('GMT');
$k=getdate();
 $target = mktime($info['hours']-2, $info['minutes'], 0, $info['month'], $info['day'], $info['year']) ;

$today = time () ;

$difference =($target-$today) ;
$days=(int) ($difference/86400) ;
$hours =(int) ($difference/3600) ;
$minutes = floor((((($difference%31556926)%2629744)%86400)%3600)/60); // remainder of hours into minutes - 60 seconds in a minute
        $seconds = floor((((($difference%31556926)%2629744)%86400)%3600)%60);
if(($seconds>-1) || ($minutes>-1))
{
	if(($minutes>=3) && ($hours>0))
	{
	
		echo "<input type='hidden' id='1' value='1' > <BR>Current Bid: ".$info['current']."<BR>Current Winner: ".$info['winner']."<BR>Time Untill Bid End: $days days $hours hours $minutes minutes $seconds seconds<br>";
	}
	if(($minutes<3) && ($hours<=0))
	{
	echo "<input type='hidden' id='1' value='2' > <BR>Current Bid: ".$info['current']."<BR>Current Winner: ".$info['winner']."<BR>Time Untill Bid End: $days days $hours hours $minutes minutes $seconds seconds<br>";
		
	}
	
}
else
{
	$_SESSION['ishit']=0;
	$data = mysql_query("DELETE FROM pubbid WHERE id='$info[id]'") or die(mysql_error());
	$q = "INSERT INTO pubbid VALUES ('$info[username]','$info[name]','$info[id]','$info[objects]','$info[type1]','$info[startprice]','$info[jump]','$info[minprice]','$info[market]','$info[time]','$info[get]','$info[pic]','close','$info[winner]','$info[current]','$info[hours]','$info[minutes]','0','$info[day]','$info[month]','$info[year]')";
	$result=mysql_query($q,$conn);
	if($info['winner']==$_SESSION['username'])
	{echo "BID IS CLOSED!<br>Winner: ".$info['winner']."<br>Congratulation!";}
	else
	{
	echo "BID IS CLOSED!<br> You Did Not Win... Try Again!";
	}	
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.