Jump to content

Please help me find mistake in this scropt


jck

Recommended Posts

$r2 = mysql_query("select RateSum,RateCount from dd_items where ItemID = '$_POST[itemID]'");
$rows = mysql_fetch_array($result);
$rc = $rows['RateCount'];
$rs = $rows['RateSum'];
$rc = $rc + 1;
$rs = $rs + '$_POST[rr]';
$nrate = $rs/$rc;
UPDATE dd_items SET RateSum = '$rs' ,RateCount = '$rc' , Rating = '$nrate' WHERE = ItemID '$_POST[itemID]';

From what I could see, I fixed the problems:

 

<?php

$r2 = mysql_query("select RateSum,RateCount from dd_items where ItemID '{$_POST['ItemID']}'");
$rows = mysql_fetch_array($result);

$rc = $rows['RateCount'];
$rs = $rows['RateSum'];
$rc = $rc + 1;
$rs = $rs + $_POST['rr'];
$nrate = $rs/$rc;

$query = "UPDATE dd_items SET RateSum = '$rs' ,RateCount = '$rc' , Rating = '$nrate' WHERE ItemID '{$_POST['ItemID']}'";
$result = mysql_query($query)or die(mysql_error());

?>

oops  :-[

 

my old system of rating was to store all votes in 1 table with itemid, username and rating i wanted to make it like this for some reasons.....

now i have a huge problem there are already 60 jokes and many votes stored in the old method any way to transfer them directly of should i feed manually ???

try this?

$sql = mysql_query("select RateSum,RateCount from dd_items where ItemID = '".$_POST[itemID]."'");
while($r = mysql_fetch_array($sql))
{
$rc = $r['RateCount'];
$rs = $r['RateSum'];
$rc2 = $rc + 1;
$rs2 = $rs + $_POST[rr];
$nrate = $rs2/$rc2;
}
mysql_query("UPDATE dd_items SET RateSum = '$rs' , RateCount = '$rc' , Rating = '$nrate' WHERE ItemID = '".$_POST[itemID]."'");

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.