<?
function bidback($pid)
{
require 'include/databaseinfo.php';
	$sql=mysql_connect($dbhost,$dbuser,$dbpass);
 	if(!$sql) {
		echo "<h1>Unable to Establish Connection to the Server</h1><hr noshade size=2 color=#000000>";
		exit();
	}
	$db_sel=mysql_select_db($dbname,$sql);
	if(!$db_sel) {
		echo "<h1>Unable to Connect to the Database</h1><hr noshade size=2 color=#000000>";
		exit();
	}

$bid_sql2="select * from site_bids where productid=".$pid." order by bidding_amount desc";
$bid_res2=mysql_query($bid_sql2);
$coun=1;
while($bid_row2=mysql_fetch_array($bid_res2))
   {
$user_bid_id2=$bid_row2['user_id'];

$user_sqlh="select * from site_bids where user_id=$user_bid_id2 and cashback='no' and bidpool='paid' and productid=".$pid;
$user_resulth=mysql_query($user_sqlh);
$cashback1=mysql_num_rows($user_resulth);
if($cashback1!=0){

if($coun >5){
$lcoun = 6;
}
if($coun <=5){
$lcoun = $coun;
}

$sqlS="select * from bidback_levels where level_id=$lcoun";
$resultS=mysql_query($sqlS);
$rowS=mysql_fetch_array($resultS);

$bidback_levels=$rowS['bidback_levels'];
$addbids = $cashback1*$bidback_levels/100;
$addbids = round($addbids, 0);


$sql = "update member_details set bid_num=bid_num+'$addbids' where user_id=".$user_bid_id2;
$result = mysql_query($sql);

$sql2 = "update site_bids set cashback='yes' where user_id=".$user_bid_id2." and productid=".$pid;
$result2 = mysql_query($sql2);

$coun++;
}}}
?>