jck Posted July 15, 2007 Share Posted July 15, 2007 $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 https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/ Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 It would help if we knew what the problem was. Link to comment https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298892 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 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 https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298894 Share on other sites More sharing options...
Oldiesmann Posted July 15, 2007 Share Posted July 15, 2007 Either change $r2 to $result or change mysql_fetch_array($result) to mysql_fetch_array($r2). Link to comment https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298895 Share on other sites More sharing options...
jck Posted July 15, 2007 Author Share Posted July 15, 2007 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 https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298902 Share on other sites More sharing options...
jck Posted July 15, 2007 Author Share Posted July 15, 2007 i guess i can write a while loop and run it once..... but the problem in that is some ItemID's in the jokes database dont exist Link to comment https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298907 Share on other sites More sharing options...
xyn Posted July 15, 2007 Share Posted July 15, 2007 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 https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298913 Share on other sites More sharing options...
jck Posted July 15, 2007 Author Share Posted July 15, 2007 thanks for the reply xyn but that had already been solved please read the further ones to see the new problem Link to comment https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298916 Share on other sites More sharing options...
xyn Posted July 15, 2007 Share Posted July 15, 2007 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 https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298932 Share on other sites More sharing options...
jck Posted July 15, 2007 Author Share Posted July 15, 2007 im planning to use rate sum if two jokes have same rate avg..... but how do i transfer from old table...... Link to comment https://forums.phpfreaks.com/topic/60094-please-help-me-find-mistake-in-this-scropt/#findComment-298935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.