Near the top of my script below the session_start(); I have this code below:
if (isset($_POST['id'])) {
$_SESSION['id'] = $_POST['id'];
}
if(isset($_SESSION['sessionNum'])){
//Declare my counter for the first time
$_SESSION['initial_session'] = $_SESSION['sessionNum'];
$_SESSION['sessionNumber'] = intval($_SESSION['sessionNum']);
$_SESSION['sessionCounting'] = 1;
}
elseif (isset($_POST['submitMarks']) && $_SESSION['sessionCounting'] < $_SESSION['sessionNumber']) {
$_SESSION['sessionCounting']++;
}
$sessionMinus = $_SESSION['sessionCounting'];
$sessionConcat = $_SESSION['sessionCounting'];
if ($sessionMinus == $_SESSION['initial_session']){
$action = 'infopenaltymarks.php';
}elseif($sessionMinus != $_SESSION['initial_session']){
$action = $_SERVER['PHP_SELF'];
}
$assessment = $_SESSION['id'] . $sessionConcat;
Now for the heading of the page I am using this code:
<h1>INDIVIDUAL MARKS FOR EACH ANSWER: ASSESSMENT (<?php echo $assessment ?>) <?php echo $sessionMinus ?> OF <?php echo $_SESSION['initial_session'] ?></h1>
Now lets say the Session Table in the database looks like this below:
SessionId SessionName
1 AAA1
2 AAA2
3 AAB
Now if you look at the table above I have multiple exams AAA1 and AAA2 and I have a single exam AAB.
Now lets say I am working on Exam AAA1, it will display the heading as below:
INDIVIDUAL MARKS FOR EACH ANSWER: ASSESSMENT (AAA1) 1 OF 2
The above heading is correct as it displays the correct exam name, and it states its the first out of the two AAA exams
When I submit the page, it will change the heading to go on the second AAA exam which is below:
INDIVIDUAL MARKS FOR EACH ANSWER: ASSESSMENT (AAA2) 2 OF 2
Again the above heading is correct.
The problem I have is if I have a single exam, or in this case the exam AAB, as it is a single exam, it does not contain a number at the end of the exam name so it is simply displayed as AAB in the DB.
But when I output the heading it displays this below:
INDIVIDUAL MARKS FOR EACH ANSWER: ASSESSMENT (AAB1) 1 OF 1
Now you can see that the above heading is incorrect as it is not exam AAB1, it should be AAB in between the brackets. So what my question is that if an exam is 1 OF 1 or in other words just a single exam, how can I remove the number 1 from the end of the exam name in between the brackets so it displays it as AAB and not AAB1?
Add the session count only if greater than 1
Fix right before printing the line