Thursday, 8 August 2013

Code setting item price to 0

Code setting item price to 0

alright, these two functions refuse to work properly for some reason and i
cannot figure out why. They work fine if used outside of an active
database (I'ved tested it and am testing it right now) but for some reason
the second they're getting their information from the database, they zero
out the price that's supposed to be updated; eg where a price should go up
to say, 20 dollars from 4, it goes to zero and then next time it updates
goes to the next number in the line.
private function updatePrice($iid, $price, $purchased)
{
if($price >= 0)
{
$price = abs($price);
}
else
{
$price = $this->getItemStats($iid);
$price = abs($price['base']);
}
$sql = "UPDATE store SET item_price = :price, available =
available-:purchased WHERE iid = :iid";
$que = $this->db->prepare($sql);
$que->bindParam('price', $price);
$que->bindParam('iid', $iid);
$que->bindParam('purchased', $purchased);
try{$que->execute(); if($que) { return true; } else { echo "FUCK";
exit; } }catch(PDOException $e){echo $e->getMessage(); exit;}
}
function getSupplyDemand($purchased, $iid)
{
$sql = "SELECT available, number, item_base_price, iid FROM store
WHERE iid = :iid";
$que = $this->db->prepare($sql);
$que->bindParam('iid', $iid);
try{ $que->execute();
if($que)
{
while($row = $que->fetch())
{
$Quantity =$row[0];
$Supply = $row[1];
$price = $row[2];
$iid = $row[3];
$price = abs(($price * $purchased)*($Quantity -
$Supply)/.25);
if($this->updatePrice($iid, $price, $purchased))
{
return true;
}
else
{
echo "Somethign went wrong";
exit;
}
}
}
}catch(PDOException $e){}
}

No comments:

Post a Comment