User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 363,826 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 154 | Replies: 2 | Solved
Reply
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Calculating Query

  #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?

<?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';

} 
 

?>

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: Calculating Query

  #2  
May 16th, 2008
<?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;

?>
Reply With Quote  
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: Calculating Query

  #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 5:11 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:00 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC