Page 1 of 1
My function does not work!
Posted: Sat Sep 27, 2008 7:42 pm
by cap2cap10

Can anyone tell me why my code doesn't work?
Code: Select all
<?php
$acc_stat= $_SESSION['js_account']['acc_stat'];
$prof_stat = $_SESSION['js_profile']['prof_stat'];
$res_stat = $_SESSION['js_resume']['res_stat'];
$pic_stat = $_SESSION['js_resume']['pic_stat'];
$file_stat = $_SESSION['js_resume']['file_stat'];
function check_progress($acc_stat, $prof_stat, $res_stat, $pic_stat, $file_stat)
{
if ($acc_stat == "yes")
{
echo "<a href=upload_profile.php > Step 2: Upload Profile NOW!</a>";
}
elseif ($acc_stat == "yes" && $prof_stat == "yes")
{
echo "<a href=upload_resume_1.php >Step 3: Upload Resume NOW!</a>";
}
elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes")
{
echo "<a href=upload_pic.php ><BR>Step 4: Upload Photo NOW!</a>";
}
elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes" && $pic_stat == "yes")
{
echo "<a href=upload_file.php >Step 5: Upload MS Word files NOW!</a>";
}
elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes" && $pic_stat == "yes" && $file_stat == "yes")
{
echo "Please activate your Candidate Portfolio!";
}
}
?>
I need it to ignore one condition when the other one is true.
it echos nothing at all.
Thanks in advance!
Batoe
Re: My function does not work!
Posted: Sun Sep 28, 2008 10:19 am
by tkj
Try this..
Code: Select all
<?php
$acc_stat= $_SESSION['js_account']['acc_stat'];
$prof_stat = $_SESSION['js_profile']['prof_stat'];
$res_stat = $_SESSION['js_resume']['res_stat'];
$pic_stat = $_SESSION['js_resume']['pic_stat'];
$file_stat = $_SESSION['js_resume']['file_stat'];
function check_progress($acc_stat, $prof_stat, $res_stat, $pic_stat, $file_stat) {
if ($acc_stat == "yes") {
echo "<a href=\"upload_profile.php\"> Step 2: Upload Profile NOW!</a>";
} elseif ($acc_stat == "yes" && $prof_stat == "yes") {
echo "<a href=\"upload_resume_1.php\">Step 3: Upload Resume NOW!</a>";
} elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes") {
echo "<a href=\"upload_pic.php\"><BR>Step 4: Upload Photo NOW!</a>";
} elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes" && $pic_stat == "yes") {
echo "<a href=\"upload_file.php\">Step 5: Upload MS Word files NOW!</a>";
} elseif ($acc_stat == "yes" && $prof_stat == "yes" && $res_stat == "yes" && $pic_stat == "yes" && $file_stat == "yes") {
echo "Please activate your Candidate Portfolio!";
}
}
?>
Re: My function does not work!
Posted: Sun Sep 28, 2008 10:53 am
by Stryks
With your stacking of if statements ... have you considered that for the second one to be true, the first one MUST be, and therefore the second would never be seen? Same with the third, etc etc.
Either reverse the if statements or do something like ...
Code: Select all
<?php
$acc_stat= $_SESSION['js_account']['acc_stat'];
$prof_stat = $_SESSION['js_profile']['prof_stat'];
$res_stat = $_SESSION['js_resume']['res_stat'];
$pic_stat = $_SESSION['js_resume']['pic_stat'];
$file_stat = $_SESSION['js_resume']['file_stat'];
function check_progress($acc_stat, $prof_stat, $res_stat, $pic_stat, $file_stat) {
if ($acc_stat == "yes") {
if($prof_stat == "yes") {
if($res_stat == "yes") {
if($pic_stat == "yes") {
if($file_stat == "yes") echo "Please activate your Candidate Portfolio!";
} else echo "<a href=\"upload_file.php\">Step 5: Upload MS Word files NOW!</a>";
} else echo "<a href=\"upload_pic.php\"><BR>Step 4: Upload Photo NOW!</a>";
} else echo "<a href=\"upload_resume_1.php\">Step 3: Upload Resume NOW!</a>";
} else echo "<a href=\"upload_profile.php\"> Step 2: Upload Profile NOW!</a>";
}
?>
That way you don't evaluate the same thing over and over, and it stops processing at the earliest possible point.
I might have reversed the messages though, I'm not too sure about the logic you used.
Anyhow ... hope this helps.
Re: My function does not work!
Posted: Sun Sep 28, 2008 5:03 pm
by cap2cap10

thanks Stryks. you were right! I reversed my code and it works perfectly. Hey, I am still a novice. Things aren't as apparent to me.

Thanks again for the help!
Batoe