I have a php function that allows user to generate a PDF certificate once all 8 modules are complete.
<?php if($sname['8']=="Yes"){ ?>
//show button to create PDF
<?php } ?>
The $sname['8'] refers to an actual table row, ie there are the following rows in DB: 1, 2, 3, 4, 5, 6, 7, 8 and each gets a 'Yes' or 'No' to indicate if passed.
But I am adding a new course which only needs 6 modules to complete. I can get the appropriate value for number of modules needed to complete in following var:
echo $courseDetails['modules']; //could be 8 or 6
Which could be 8 or 6 depending on course. So I need to change the following to use the $courseDetails['modules'] instead of the hard coded '8', but I don't understand the syntax for making this happen.
eg
//if($sname['8']=="Yes"){
if($sname['$courseDetails['modules']']=="Yes"){
if($sname[" . $courseDetails['modules'] . "]=="Yes"){
Any help appreciated.
I would suggest that you use a numeric array instead of your current associative version. Currently you use a string key (valued '1'
,'2'
,'3'
,..). Altghough possible with an associative array, using a numeric array would simplify the task of determining the array's length and handling its individual elements.
In order to find out how many criteria there are to pass you could use
$criteria=array('No','No','No','No','No','No'); // define the criteria
// Now, check how many elements there are:
$critcount=count($criteria) // = 6
However, you need to know that the first element in the array has the index 0
and not 1
, so to check the sixth element you would do:
$num=6;
if(criteria[$num-1]=="Yes"){ /* do something */ }