| | |
Calculating Query
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 11
Reputation:
Solved Threads: 0
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?
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)
<?php $age = 21 if ($age >61) { echo '0.5'; } elseif (($age >= 51) && ($age <= 60)) { echo '1.0'; } elseif ($age <= 21) { echo '2.5'; } elseif (($age >= 31) && ($age <= 50)) { echo '1.5'; } elseif ($age >= 60) { echo '1.5'; } elseif (($age >= 22) && ($age <= 30)) { echo '2.0'; } ?> <BR> <?php $mc = 0 if ($mc == 0) { echo '0.5'; } elseif (($mc >= 1) && ($mc <= 2)) { echo '1.0'; } elseif ($mc >2) { echo '1.5'; } ?>
PHP Syntax (Toggle Plain Text)
<?php $age = 21; if ($age >61) { $age_score = '0.5'; } elseif (($age >= 51) && ($age <= 60)) { $age_score = '1.0'; } elseif ($age <= 21) { $age_score = '2.5'; } elseif (($age >= 31) && ($age <= 50)) { $age_score = '1.5'; } elseif ($age >= 60) { $age_score = '1.5'; } elseif (($age >= 22) && ($age <= 30)) { $age_score = '2.0'; } ?> <BR> <?php $mc = 0; if ($mc == 0) { $crash_score = '0.5'; } elseif (($mc >= 1) && ($mc <= 2)) { $crash_score = '1.0'; } elseif ($mc >2) { $crash_score = '1.5'; } $total=$age_score + $crash_score; echo "age score $age_score <br>"; echo "crash score $crash_score <br>"; echo "total score ".$total; ?>
![]() |
Similar Threads
- Perform a calculation in a query (MS Access and FileMaker Pro)
- My PHP math is calculating weird! (PHP)
- help in sql query (PHP)
- Calculating relevance from a search (PHP)
- Warning: mysql_num_rows(): (PHP)
Other Threads in the PHP Forum
- Previous Thread: show data from database in a marquee
- Next Thread: Stupid error!!!
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






