943,832 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 538
  • PHP RSS
May 16th, 2008
0

Calculating Query

Expand Post »
Hello everyone, just got a query regarding calculating

I'm building a form and depending on how you fill it in you are given a score, currently i am using if/else statements.

Here is an example

$age is taken from the database after the form is completed (persons age)
$mc is taken from the database after the form is completed (regarding a car crash in the last 3 years)

$age = say im 21 for example the outcome would be 2.5
$mc = I havent crashed my car in the past 3 years so my score would be 0.5

Can these two results be added together giving a total of 3.0?

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $age = 21
  4.  
  5. if ($age >61)
  6.  
  7. {
  8.  
  9. echo '0.5';
  10.  
  11. }
  12.  
  13. elseif (($age >= 51) && ($age <= 60))
  14.  
  15. {
  16.  
  17. echo '1.0';
  18.  
  19. }
  20.  
  21. elseif ($age <= 21)
  22.  
  23. {
  24.  
  25. echo '2.5';
  26.  
  27. }
  28.  
  29. elseif (($age >= 31) && ($age <= 50))
  30.  
  31.  
  32. {
  33.  
  34. echo '1.5';
  35.  
  36. }
  37.  
  38. elseif ($age >= 60)
  39.  
  40. {
  41.  
  42. echo '1.5';
  43.  
  44. }
  45.  
  46. elseif (($age >= 22) && ($age <= 30))
  47.  
  48. {
  49.  
  50. echo '2.0';
  51.  
  52. }
  53.  
  54. ?>
  55.  
  56. <BR>
  57.  
  58. <?php
  59.  
  60. $mc = 0
  61.  
  62. if ($mc == 0)
  63.  
  64. {
  65.  
  66. echo '0.5';
  67.  
  68. }
  69.  
  70. elseif (($mc >= 1) && ($mc <= 2))
  71.  
  72. {
  73.  
  74. echo '1.0';
  75.  
  76. }
  77.  
  78. elseif ($mc >2)
  79.  
  80. {
  81.  
  82. echo '1.5';
  83.  
  84. }
  85.  
  86.  
  87. ?>
Similar Threads
oku
Reputation Points: 10
Solved Threads: 0
Newbie Poster
oku is offline Offline
11 posts
since May 2008
May 16th, 2008
0

Re: Calculating Query

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $age = 21;
  4.  
  5. if ($age >61)
  6.  
  7. {
  8.  
  9. $age_score = '0.5';
  10.  
  11. }
  12.  
  13. elseif (($age >= 51) && ($age <= 60))
  14.  
  15. {
  16.  
  17. $age_score = '1.0';
  18.  
  19. }
  20.  
  21. elseif ($age <= 21)
  22.  
  23. {
  24.  
  25. $age_score = '2.5';
  26.  
  27. }
  28.  
  29. elseif (($age >= 31) && ($age <= 50))
  30.  
  31.  
  32. {
  33.  
  34. $age_score = '1.5';
  35.  
  36. }
  37.  
  38. elseif ($age >= 60)
  39.  
  40. {
  41.  
  42. $age_score = '1.5';
  43.  
  44. }
  45.  
  46. elseif (($age >= 22) && ($age <= 30))
  47.  
  48. {
  49.  
  50. $age_score = '2.0';
  51.  
  52. }
  53.  
  54. ?>
  55.  
  56. <BR>
  57.  
  58. <?php
  59.  
  60. $mc = 0;
  61.  
  62. if ($mc == 0)
  63.  
  64. {
  65.  
  66. $crash_score = '0.5';
  67.  
  68. }
  69.  
  70. elseif (($mc >= 1) && ($mc <= 2))
  71.  
  72. {
  73.  
  74. $crash_score = '1.0';
  75.  
  76. }
  77.  
  78. elseif ($mc >2)
  79.  
  80. {
  81.  
  82. $crash_score = '1.5';
  83.  
  84. }
  85.  
  86. $total=$age_score + $crash_score;
  87. echo "age score $age_score <br>";
  88. echo "crash score $crash_score <br>";
  89. echo "total score ".$total;
  90.  
  91. ?>
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
amigura is offline Offline
71 posts
since Jan 2008
May 16th, 2008
0

Re: Calculating Query

i'll test this now bud, if it works ill rep and mark as solved

This was fantastic! excellent!!
Last edited by oku; May 16th, 2008 at 6:11 pm.
oku
Reputation Points: 10
Solved Threads: 0
Newbie Poster
oku is offline Offline
11 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: show data from database in a marquee
Next Thread in PHP Forum Timeline: Stupid error!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC