ic3d
09-14-2006, 06:27 PM
Hello everyone,
Currently iam learning PHP. Since i've just started iam really at the very beginnerslevel so my appologies in front for the newbie question. :)
I've created a small program that let's visitors fill out a form and based on that form gives advices and a summary. It's completely working, but since iam new, i don't have the feeling iam doing it the right way. Perhaps you guys could help me out a bit, because i don't want to learn things the wrong way :)
Below i'll have some parts of the program that i doubt are correct. Under each part is a question.
Get the string from the field
$question1=$_REQUEST['question1'];
$question2=$_REQUEST['question2'];
etc etc.
Question: Since there are like 25 fields it's becomming a long list, is it possible to make it shorter somehow?
Making a summary of the questions answered with "Yes" and with "No"
if ($question1=="Yes") $positive++;
else $negative++;
if ($question2=="yes") $positive++;
else $negative++;
etc.
etc.
echo "Questions answered with yes $positive , Questions answered with no $negative";
Do i really have to get trough the whole list or is there some function that could count the ammount of "Yes" and "No"?
Giving an advice to each question answered with "Yes":
if ($question1=="Yes") echo "Advice <br>"; else echo "";
if ($question2=="Yes") echo "Advice <br>"; else echo "";
if ($question3=="Yes") echo "Advice <br>"; else echo "";
if ($question4=="Yes") echo "Advice <br>"; else echo "";
etc etc.
Question: I think the else is completely useless but i need it in order to run the program. What iam looking for is some kind of AND function. I tried stuff like below but obviously it isn't working. Is there something possible like this or is what iam doing correct already?
if ($question1=="Yes") echo "Advice <br>";
AND if ($question2=="Yes") echo "Advice <br>";
etc
Currently iam learning PHP. Since i've just started iam really at the very beginnerslevel so my appologies in front for the newbie question. :)
I've created a small program that let's visitors fill out a form and based on that form gives advices and a summary. It's completely working, but since iam new, i don't have the feeling iam doing it the right way. Perhaps you guys could help me out a bit, because i don't want to learn things the wrong way :)
Below i'll have some parts of the program that i doubt are correct. Under each part is a question.
Get the string from the field
$question1=$_REQUEST['question1'];
$question2=$_REQUEST['question2'];
etc etc.
Question: Since there are like 25 fields it's becomming a long list, is it possible to make it shorter somehow?
Making a summary of the questions answered with "Yes" and with "No"
if ($question1=="Yes") $positive++;
else $negative++;
if ($question2=="yes") $positive++;
else $negative++;
etc.
etc.
echo "Questions answered with yes $positive , Questions answered with no $negative";
Do i really have to get trough the whole list or is there some function that could count the ammount of "Yes" and "No"?
Giving an advice to each question answered with "Yes":
if ($question1=="Yes") echo "Advice <br>"; else echo "";
if ($question2=="Yes") echo "Advice <br>"; else echo "";
if ($question3=="Yes") echo "Advice <br>"; else echo "";
if ($question4=="Yes") echo "Advice <br>"; else echo "";
etc etc.
Question: I think the else is completely useless but i need it in order to run the program. What iam looking for is some kind of AND function. I tried stuff like below but obviously it isn't working. Is there something possible like this or is what iam doing correct already?
if ($question1=="Yes") echo "Advice <br>";
AND if ($question2=="Yes") echo "Advice <br>";
etc
