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]';

Link to comment
Share on other sites

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());

?>

Link to comment
Share on other sites

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 ???

Link to comment
Share on other sites

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]."'");

Link to comment
Share on other sites

Lol i did, but it must have sent that one instead.

 

I'd advise doing 2 fields in your jokes table called "timesvoted" and "rating"

set rating as "0.0" by default. then just add the number of votes...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.