<?php

include("include/db.inc.php"); 

include("include/functions.php"); 

   $db1=new db;

   $db1->open();

   mysql_query("SET NAMES 'utf8'"); 		





set_time_limit (0);



$q=1;

while($q < 61)

{

bidbutler();

sleep(1);

$q++;

}



function bidbutler()

{

//$r=rand(4,11);

$r=rand(2,3);



 $res=mysql_query("SELECT distinct(b.uid),b.id, t.`pid` 

FROM t123go_product t

INNER JOIN t123go_butler b ON b.pid = t.pid

AND bider_id != b.uid

WHERE  max_price > bid_price

AND min_price < bid_price

AND TIME_TO_SEC( TIMEDIFF( end_time,NOW() ) ) <= $r and end_time > NOW() and no_bids > 0 order by rand()");

 

 if(mysql_num_rows($res)>0)

 {

    $x=1;

    while($prec=mysql_fetch_array($res))

	{	

	$bidrec=mysql_fetch_array(mysql_query("select no_bids from user where id='".$prec[uid]."'"));

	$numbids=$bidrec[0];

	

	if($numbids > 0)

	{

	

	 	$rec=mysql_fetch_array(mysql_query("select date_format(end_time,'%Y-%m-%d %H:%i:%s')as et ,bid_price,type1,total_bids from t123go_product where pid='$prec[pid]'"));

	

		$bid_incr=get_increment($rec['type1'],$rec['total_bids']);	  

	

	 	$price=$rec['bid_price'] + $bid_incr[0];	

	

		 mysql_query("insert into t123go_bid set uid='$prec[uid]',pid='$prec[pid]',product_price='$price',bid_time=now(),

		 type='bidbutler'");

		 

		 mysql_query("update user set no_bids=no_bids-1 where id='".$prec[uid]."'");

		 

		 mysql_query("update t123go_butler set no_bids=no_bids-1 where uid='".$prec[uid]."' and pid='".$prec[pid]."'");	 

	 

		if($x==1)

		{

		 mysql_query("update t123go_product set end_time=DATE_ADD('$rec[et]', INTERVAL $bid_incr[1] SECOND),

		   bid_price='$price',bider_id='$prec[uid]',total_bids=total_bids+1,bid_type='bidbutler' where pid='$prec[pid]'")or die(mysql_error());

		}

		else

		{

		mysql_query("update t123go_product set bid_price='$price',bider_id='$prec[uid]',total_bids=total_bids+1,

		bid_type='bidbutler' where pid='$prec[pid]'")or die(mysql_error());

		}

	}	

	

	

	$x++;  

	}  

 } 





}



//   * * * * * /home/influx/public_html/butler.php               //

?>

