Hello everyone,

I currently have a form that for each question you answer it gives u a score using if/else statements - it works fine

this form is split into differnet sections and what i need is for only 1 of the scores to display

for example in the first section the score you can get for each question is either

0.5, 1, 1.5, 2

So if whoever uses the form fills in lets say 4 questions and he gets a score of

Question 1 - 0.5
Question 2 - 2
Question 3 - 0.5
Question 4 - 1

The only score i want listing in this example would be 2

This is the if/else statement i use

<?php
 

if ($age >= 61) 

{

 $age_score = '1.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 >= 22) && ($age <= 30)) 

{

 $age_score = '2.0';

} 

?>

<?php
 

if ($dlh >15) 

{

$dlh_score = '0.5';

} 

elseif (($dlh >= 11) && ($dlh <= 15)) 

{

$dlh_score = '1.0';

} 

elseif (($dlh >= 6) && ($dlh <= 10)) 

{

$dlh_score = '1.5';

} 

elseif (($dlh >= 2) && ($dlh <= 5)) 

{

$dlh_score = '2.0';

} 

elseif ($dlh <2) 

{

$dlh_score = '2.5';

} 
 

?>

<?php
 

if ($sc == 0) 

{

$sc_score = '0.5';

} 

elseif (($sc >= 1) && ($sc <= 2)) 

{

$sc_score = '1.5';

} 

elseif ($sc >2) 

{

$sc_score = '2.0';

} 
 

?>

<?php
 

if ($mc == 0) 

{

$mc_score = '0.5';

} 

elseif (($mc >= 1) && ($mc <= 2)) 

{

$mc_score = '1.0';

} 

elseif ($mc >2) 

{

$mc_score = '1.5';

} 
 

?>

Many thanks in advance

Recommended Answers

All 2 Replies

You can make use of max function to get the maximum value. http://nl3.php.net/max
This would be easy if you store the scores in an array and use max to get the maximum value.

Many thanks nav33n - i've been reading through the link you have provided but i am struggling to impliment it into my script - the example that i believe would work is http://nl3.php.net/manual/en/function.max.php#58565 - any more advice would be great,

many thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.