/    Sign up×
Community /Pin to ProfileBookmark

PHP/Javascript calculator error

Hey there,

I’m facing a problem with a calculator on my site, you can see it here: [url]http://axa.seomena.com/fr/calculez-vos-primes/calculez-vos-primes-assurances-medicales[/url]

The problem is, when you choose the “number of family” whether you’re a family of 1 or a family of 6 and more, (in the next step) if you choose anything but “Class SP” the calculation will work, but if you choose “Class SP” in the “Montant Police(US$)” cell instead of printing a value number it just says “NAN”, I donno what’s the problem with it but I’m assuming it’s something to do with the php or some missing values in phpmyadmin.

If you notice in the image attached below that when “Class_type_id” is equal to “5” the “family_type_id” is always equal to 0. class_type_id 5 represent the “Class SP”.

Here is the code

[code]ksort($counter);
foreach ($counter as $nb=>$data){

//echo $age_range_id[$nb].’–‘.$class_type_id[$nb].’–‘.$nssf[$nb].’–‘.$amb[$nb].’–‘.$med[$nb].’–‘.$doc[$nb].’ ||||||| ‘;
//echo $nb;
//if((!$age_range_id[$nb-1])||(!$class_type_id[$nb]))continue;
if($nssf[$nb]==”on”)$add=”and nssf=1″;
else $add=”and nssf=0″;

if(($amb==”on”) && ($age_range_id[$nb-1]))$get_amount_amb=id2fields(“amb_plan”,”amount”,”family_type_id=$family_type_id and age_range_id =”.$age_range_id[$nb-1].””);
if(($med==”on”) && ($age_range_id[$nb-1]))$get_amount_med=id2fields(“pre_med_plan”,”amount”,”family_type_id=$family_type_id and age_range_id =”.$age_range_id[$nb-1].””);
if(($doc==”on”) && ($age_range_id[$nb-1]))$get_amount_doc=id2fields(“doc_plan”,”amount”,”family_type_id=$family_type_id and age_range_id =”.$age_range_id[$nb-1].””);

//echo $get_amount_amb.’~~~’.$get_amount_med.’~~~’.$get_amount_doc.'<br>’;

if($class_type_id[$nb]<>5){ // NO class SP

if($age_range_id[$nb-1])$get_amount=id2fields(“policy”,”amount”,
“age_range_id=”.$age_range_id[$nb-1].” and class_type_id=”.$class_type_id[0].” and family_type_id=$family_type_id $add”);

}
else { // Class SP

if($age_range_id[$nb-1])$get_amount=id2fields(“policy”,”amount”,
“age_range_id=”.$age_range_id[$nb-1].” and class_type_id=”.$class_type_id[0].” $add”);

}
$sum_amount=$get_amount+$get_amount_amb+$get_amount_med+$get_amount_doc;
/*echo “<b>”.($get_amount?$get_amount:”NaN”).($get_amount_amb?”- $get_amount_amb “:””).($get_amount_med?” – $get_amount_med “:””).($get_amount_doc?” – $get_amount_doc total : —-> $sum_amount “:””).”</b>”;
echo “<br>”;*/

//echo “==>”.$age_range_id[$nb-1].'<br>’;

if($age_range_id[$nb-1]){
echo “<tr>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.$nb.”</td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.($get_amount?number_format($get_amount,2,’.’,’,’):”NAN”).”</td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.($get_amount_amb?$get_amount_amb:”&nbsp; “).”</td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.($get_amount_med?$get_amount_med:”&nbsp; “).”</td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.($get_amount_doc?$get_amount_doc:”&nbsp; “).”</td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’>”.number_format($sum_amount,2,’.’,’,’).”</td>
<input type=’hidden’ name=’amnt[$nb]’ value=’$get_amount’/>
<input type=’hidden’ name=’amnt_amb’ value=’$get_amount_amb’/>
<input type=’hidden’ name=’amnt_med’ value=’$get_amount_med’/>
<input type=’hidden’ name=’amnt_doc’ value=’$get_amount_doc’/>
<input type=’hidden’ name=’sum[$nb]’ value=’$sum_amount’/>
<input type=’hidden’ name=’nb[$nb]’ value=’$nb’/>
</tr>”;

$total+=$sum_amount;
}

}
echo “<tr>
<td align=’right’ colspan=’5′ id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’><b> &nbsp;&nbsp;&nbsp; Total des primes:</b></td>
<td id=’policytd’ style=’font-size: 10pt; line-height:11pt; font-family:tahoma;’><b>”.number_format($total,2,’.’,’,’).”</b></td>
</tr>
“;

echo “</table></center><br><br>”;

echo ‘
<table>
<tr><td style=”font-size: 8pt; line-height:11pt; font-family:tahoma” colspan=”2″ id=”seperator”>Veuillez remplir les informations suivantes pour qu’un de nos agents vous contacte. </td></tr>
<tr><td style=”font-size: 8pt; line-height:11pt; font-family:tahoma”>Nom :</td><td align=”left”> <input type=”text” name=”nom”/></td>
</tr>
<tr>
<td style=”font-size: 8pt; line-height:11pt; font-family:tahoma”>Pr&eacute;nom :</td><td align=”left”> <input type=”text” name=”prenom”/></td>
</tr>
<tr>
<td style=”font-size: 8pt; line-height:11pt; font-family:tahoma”>No.Cellulaire :</td><td align=”left”> <input type=”text” name=”phone”/></td>
</tr>
<tr>
<td colspan=”2″>&nbsp;</td>
</tr>
<tr>
<td style=”font-size:12px; font-family:tahoma” width=”60%” id=”lasttdpadd” colspan=”2″>
<input type=”submit” value=”Soumettre” name=”submit”/>
<input type=”hidden” value=”true” name=”sendmail”/>
<input type=”hidden” value=”‘.$total.'” name=”total”/>
</td>
</tr>
</table><br><br><br><br><br><br><br><br><br><br><br><br><br></form>
‘;
exit;

}

if((($_POST[“step”]==1)&&($_POST[“sbm”]==’Étape suivante’))||($_POST[“class_type_id”])){
//printR($_POST);[/code]

Thanks.

[upl-file uuid=9cbd0fc1-4d98-4b88-9af3-c5cdbf23566d size=32kB]classtype.jpg[/upl-file]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@drugoholicauthorAug 13.2009 — I think the problem is here:

if($class_type_id[$nb]&lt;&gt;5){ // NO class SP

<i> </i> if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
<i> </i> "age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." and family_type_id=$family_type_id $add");

<i> </i> }
<i> </i> /*else { // Class SP

<i> </i> if($age_range_id[$nb-1])$get_amount=id2fields("policy","amount",
<i> </i> "age_range_id=".$age_range_id[$nb-1]." and class_type_id=".$class_type_id[0]." and family_type_id=$family_type_id $add");

<i> </i> }*/
<i> </i> else { // Class SP

<i> </i> $get_amount=id2fields("policy","amount",
<i> </i> "age_range_id=".$age_range_id[$nb]." and class_type_id=".$class_type_id[$nb]." and family_type_id=".$family_type_id[$nb]." $add");

<i> </i> }


As you can see if $class_type_id is not equal to 5, it has a different function and I think the function is wrong. I tried to use 2 different ones with no luck so far.
×

Success!

Help @drugoholic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...