I have this code below:
$insert = array();
for ($i = 1, $n = $_POST['sessionNum']; $i <= $n; ++$i)
{
if( $_POST['sessionNum'] == '1'){
$insert[] = "'" . mysql_real_escape_string($_POST['id']) . ($i == 1 ? '' : $i) . "'";
}else{
$insert[] = "'" . mysql_real_escape_string($_POST['id']) . "'";
}
$insert[] .= "' ". mysql_real_escape_string( $_POST['textMarks'] ) . "'";
}
$sql = "INSERT INTO Session (SessionId, TotalMarks)
VALUES (" . implode('), (', $insert) . ")";
mysql_query($sql);
What the code above does is that it adds a number next to the $_POST[‘id’] depending on what the number is in the $_POST[‘sessionNum’].
For example if $_POST[‘sessionNum’] is ‘3’ and $_POST[‘id’] is VBV, then it will display ‘VBV3’.
But what I want is that if $_POST[‘sessionNum’] is ‘1’, I do not want it to display ‘VBV1’ but instead just ‘VBV’ as it is a single session.
How can this be achieved?
1 Answer