mazman13 Posted October 5, 2007 Share Posted October 5, 2007 Ok. So I'm writing a program for a bodyshop. Customers are asked 11 questions all with yes or no answers. Yes is good, no is bad. From that they can take the overall % for the month and see what the approve rating is. I had a format I thought was going to work but as I got into it, it doesn't seem like it is going to work. Example: $a = 10; // How many questions did he answer yes to $b = 357; // How many customers they had this month Format: $c = ($a * 100) / $b; echo"$c"; OUTPUT = 2.8% But that is just one customer. If I tallied up all the yes answers eventually they would be more than what I'm dividing them by and defeat the function. What should I do? Any ideas? We also want a way to track the overall approval rating for the past 12 months. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/ Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 If you want to work out the % approval for the month you need to take into consideration of all customer who answered yes. I am a little confused though Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362374 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 Yeah, I just used that one for an example. Lets say there was 780 questions that were answered yes by 350 customers... That formula wouldn't work. So I need a better way to do this. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362376 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 What do you want to work out from the results Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362379 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 I just want to know the % of yes (approval) for each customer as well the overall % for that month and the past 12 months. I just need to find a good game plan Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362382 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 ok you are working out the percent wrong you should do this $a = number of yes $b = number of No $c = total //percent of yes $d = ($a/$c)*100 This is for the individual customers Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362385 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 What do you do for the over all customer %? Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362387 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 the one i just gave you is for the overall individual customer approval. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362389 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 For the month and the 12month one i am persuming you want a result that represent all of the customers Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362390 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 Correct. Maybe the total % of all customers combined. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362397 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 to get the total % of all customers approved in the month $a = total number of customer approved $b = total number of customers not approved $C = $a + $c //basically the total number of customer who you have asked questions too $d = ($a/$C) * 100 Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362403 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 Well I dont' know how that would work. Because lets say I have five customers. 1) 35.7% 2) 93.6% 3) 99.2% 4) 100% 5) 78.4% I want to talley all of them up for an average for the month. What can I do? And how can I do it with a couple of hundred customers a month? Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362414 Share on other sites More sharing options...
php_joe Posted October 5, 2007 Share Posted October 5, 2007 when are you going to work up the percentage? Each time a customer enters their info? Or at the end of the month? You could use the $d = ($a/$c) * 100; formula above to get each person's answers. If you placed the answers into an array as customers submitted their answers you could figure out the percentages in "real time" $month = (array_sum($d) / count($d)) * 100; Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362419 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 You will need to do a seperate calculation. Dont take their percentages. Instead add up the total number of customers you have asked questions to, lets say 750. Then take the total number of customers that had been approved, lets say 556. Then do (556 / 750) *100 Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362421 Share on other sites More sharing options...
mazman13 Posted October 5, 2007 Author Share Posted October 5, 2007 I'll try them out. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362426 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 Surely if you ask 100 customers 10 questions each, then the total number of questions asked is 1000. If overall 300 questions were answered with a yes, then you need to work out the percentage that 300 is of 1000: <?php $customers = 100; $questions = 10; $total_questions = $customers * $questions; $positive_answers = 300; $percentage = $positive_answers/$total_questions *100; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362440 Share on other sites More sharing options...
adam291086 Posted October 5, 2007 Share Posted October 5, 2007 Yeah that looks fine although make sure you put brackets around <?php $customers = 100; $questions = 10; $total_questions = $customers * $questions; $positive_answers = 300; $percentage = ($positive_answers/$total_questions) *100; ?> Not sure if that will work to be honest. but you need to ensure $positive_answers/$total_questions is calculated first. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362446 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 but you need to ensure $positive_answers/$total_questions is calculated first. No you don't. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362544 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 GingerRobot is correct. Quote Link to comment https://forums.phpfreaks.com/topic/71952-need-help-with-some-php-math/#findComment-362549 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.