0

aww. i'm so sorry for posting again. i have so many questions. i'm so sorry. ahm. i was just wondering if my code is possible if ever i'm going to insert a remarks to my database.

here is my code:

$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

if(totalg <= 5.00 && totalg >= 4.51){
	$remark=Excellent;}
else(totalg <= 4.50 && totalg >= 3.51){
	$remark=Very Satisfactory;}
else(totag <= 3.50 && totalg >= 2.51){
	$remark=Satisfactory;}
else(totalg <= 2.50 && totalg >= 1.51){
	$remark=Fair;}
else(totalg <= 1.50 && totalg >= 1.00){
	$remark=Needs Improvement;}

i think it's possible but i have this parse error. i don't know where. please and thank you so much. :)

3
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by miss_indie
1

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

Edited by hielo: n/a

1

You need to change 'else' to 'elseif' for each of the statements.

as hielo suggested, Quotation marks are required around the remark values

Also 'totalg' needs the '$' prefix! It is a variable.

Edited by nonshatter: n/a

0

Sort out your indentation and curly braces - It makes things much easier to read and debug...

<?php
	$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

	if($totalg <= 5.00 && $totalg >= 4.51)
	{
		$remark="Excellent";
	}
	elseif($totalg <= 4.50 && $totalg >= 3.51)
	{
		$remark="Very Satisfactory";
	}
	elseif($totag <= 3.50 && $totalg >= 2.51)
	{
		$remark="Satisfactory";
	}
	elseif($totalg <= 2.50 && $totalg >= 1.51)
	{
		$remark="Fair";}
	elseif($totalg <= 1.50 && $totalg >= 1.00)
	{
		$remark="Needs Improvement";
	}

	echo $remark;
?>

Edited by nonshatter: n/a

0

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

oh. okay. my bad. so i changed all the codes so here is my new code:

$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

if($totalg <= 5.00 && $totalg >= 4.51){
	$remark="Excellent";}
elseif($totalg <= 4.50 && $totalg >= 3.51){
	$remark="Very Satisfactory";}
elseif($totalg <= 3.50 && $totalg >= 2.51){
	$remark="Satisfactory";}
elseif($totalg <= 2.50 && $totalg >= 1.51){
	$remark="Fair";}
else($totalg <= 1.50 && $totalg >= 1.00){
	$remark="Needs Improvement";}

But i have parse error on the else part.

0

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

oh yes. yes po. i already did but i have parse error on the else part.

0

there is no such thing as:
else OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

the proper syntax for an else is a "braced block" with NO condition:
else{
...
}

there is:
if OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

and also
elseif OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

so if you really want to include that condition, you should use and elseif

Edited by hielo: n/a

0

there is no such thing as:
else OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

the proper syntax for an else is a "braced block" with NO condition:
else{
...
}

there is:
if OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

and also
elseif OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

so if you really want to include that condition, you should use and elseif

oh. okay. that worked but i have this error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2

what does that mean? i'm so sorry.. and thank you so much. :)


OH. okay. i knew it already. :) thank you so much for the help guys! ! :)

Edited by miss_indie: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.