Jump to content

Recommended Posts

Whay is this giving me the wrong calculation? I am trying to work out the percentage of positive feedback this should be giving me 50% but is outputting at 40%

 

 

The structure of feedback is like this:

 

user_id,score,Comment,from_id,id,get_date_proid

 

The important fields here are user_id and score

 

Score works like this:

1= positive

2= negative

3= neutral

 




$feed="select * from feedback WHERE user_id=$userid and score=1 OR score=2";
//echo $freetplquery;
$sum=mysql_query($feed);
$feedpercent=mysql_fetch_array($sum);
    

$num_rows = mysql_num_rows($sum); 



$feedback="select * from feedback WHERE user_id=$userid and score=1";
//echo $freetplquery;
$possum=mysql_query($feedback);
$feedscore=mysql_fetch_array($possum);
    

$num_pos = mysql_num_rows($possum); 


$score+= (($num_pos / $num_rows) * 100);

 

 

 

Im guessing its my sum thats incorrect but am unsure

 

 

$feedback="select * from feedback WHERE user_id=$userid and score=1";

 

should be

 

$feedback="select COUNT(*) from feedback WHERE user_id=$userid and score=1";

 

 

 

$feed="select * from feedback WHERE user_id=$userid and score=1 OR score=2";

 

should be

 

$feed="select COUNT(*) from feedback WHERE user_id=$userid and score=1 OR score=2";

 

That may help.

Thanks It still wasnt calculating right so in the end i took out the 'OR' part and added the two together instead, it seems to be giving me the right percentage at last  ;D

						   
$feed="SELECT count(*) from feedback WHERE user_id=$user_id and score=2";
$sum=mysql_query($feed);
$feedpercent=mysql_fetch_array($sum);
$num_rows = mysql_num_rows($sum); 



$feedback="SELECT count(*) from feedback WHERE user_id=$user_id and score=1";
$possum=mysql_query($feedback);
$feedscore=mysql_fetch_array($possum);   
$num_pos = mysql_num_rows($possum); 

$addsum+= $num_rows + $num_pos;


$score+= (($num_pos / $addsum) * 100); 

 

 

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.