jck Posted July 12, 2007 Share Posted July 12, 2007 <? require_once("conn.php"); //check the user ??? $q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and username = '$_SESSION[username]' "; $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) == '0') { $q2 = "insert into dd_rating set ItemID = '$_POST[itemID]', Rating = '$_POST[rr]', username = '$_SESSION[username]' "; mysql_query($q2) or die(mysql_error()); $q3 = "select rating from dd_items where ItemID = '$_POST[itemID]' "; $r3 = mysql_query($q3); $rating = mysql_fetch_array($r3); $q4 = "select ratecount from dd_items where ItemID = '$_POST[itemID]'"; $r4 = mysql_query($q4) $ratecount = mysql_fetch_array($r4); $ratecountn = $ratecount + 1; $ratingn = $rating*$ratecount/$ratecountn; $q5 = "UPDATE dd_items SET rating='$ratingn where ItemID = '$_POST[itemID]'"; $r5 = mysql_query($q5); header("location:$_SERVER[HTTP_REFERER]&rate_error=n"); } else { header("location:$_SERVER[HTTP_REFERER]&rate_error=y"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/ Share on other sites More sharing options...
cooldude832 Posted July 12, 2007 Share Posted July 12, 2007 This is not test/rate my script forumn this is help forumn you don't say is this right you say I've got a problem here in my code any ideas? If you want to test/rate move to raters boards please Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296663 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 somebody please answer Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296684 Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 somebody please answer What is the question/problem? There is neither in the post above. If you want help/an answer please post what is going wrong, where you think it is going wrong and what steps you have already taken to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296686 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 the script is nor working Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296687 Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 the script is nor working Not going to work. Why isn't it working, how isn't it working. What part about it do you think is not working? This isn't, here is a bunch of code, find the error for me forum. This is the help forum. We will help you, but first you need to put forth the effort and ask the question the right way. Just informing you that you won't get an answer till you are clearer on the issue and not just say "Here is a haystack, please find the needle for me." Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296690 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 i mean im not sure about how to extract one value from the table like rating Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296704 Share on other sites More sharing options...
shamilton Posted July 12, 2007 Share Posted July 12, 2007 If your script produces an error please post that. If it is not posting an error and you are having trouble with the logic - please post a detailed description of what you are trying to do. We are freaks here...not psychics... Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296706 Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 ok ignore that code and see this 2 feilds in a table called rating and rate count the value of rating sould be added to the new vote and the value of ratecount should increase by one Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296709 Share on other sites More sharing options...
sasa Posted July 12, 2007 Share Posted July 12, 2007 can one user vote multiple time for same item? Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296780 Share on other sites More sharing options...
jck Posted July 13, 2007 Author Share Posted July 13, 2007 no Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-296954 Share on other sites More sharing options...
sasa Posted July 13, 2007 Share Posted July 13, 2007 try <? session_start(); require_once("conn.php"); //check the user ??? $q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and username = '$_SESSION[username]' "; $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) == '0') { // update db $q2 = "insert into dd_rating set ItemID = '$_POST[itemID]', Rating = '$_POST[rr]', username = '$_SESSION[username]' "; mysql_query($q2) or die(mysql_error()); echo 'rating updated'; } else echo 'You can not vote for ',$_POST['ItemID']; $q3 = "select count(*) as count, sum(Rating) as total, avg(Rating) AS av_rate from dd_items where ItemID = '$_POST[itemID]' "; $r3 = mysql_query($q3); $rating = mysql_fetch_array($r3); if (mysql_num_rows($rating) == 0) echo $_POST['ItemID'] , 'has no votes'; else { echo ' voting for ', $_POST['ItemID'],'<br />', 'total points: ', $rating['total'], '<br />', 'num of vaters: ', $rating['count'], '<br />', 'average: ', $rating['av_rate']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59686-solved-what-is-the-mistake-in-this-script/#findComment-297048 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.