Calculating Query

Thread Solved

Join Date: May 2008
Posts: 11
Reputation: oku is an unknown quantity at this point 
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Calculating Query

 
0
  #1
May 16th, 2008
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?

  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: Calculating Query

 
0
  #2
May 16th, 2008
  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. ?>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 11
Reputation: oku is an unknown quantity at this point 
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: Calculating Query

 
0
  #3
May 16th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC