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]'; Quote Link to comment 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. Quote Link to comment 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()); ?> Quote Link to comment 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). Quote Link to comment 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 ??? Quote Link to comment 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 Quote Link to comment 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]."'"); Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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...... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.