I am fairly new to php. I am trying to update the score everytime I loop over this array. my code only works if the first value of the listbox was selected by the user and it gives a zero if its not selected. please help.
This is A.php
{
$SkillsArray = array();
$Score=0;
$SkillsArray = $_POST['DutiesDesc'];
//foreach($SkillsArray as $key =>$value )
{
$Sentence = $SkillsArray[0]." ".$SkillsArray[1]." ".$SkillsArray[2]." ".$SkillsArray[3]." ".$SkillsArray[4]." ".$SkillsArray[5]." ".$SkillsArray[6]." ".$SkillsArray[7 ]." ".$SkillsArray[8]." ".$SkillsArray[9]." ".$SkillsArray[10];
}
//Get the applicants score
for($i=0;$i<11;$i++)
{
if ($SkillsArray[$i] == $Text[$i])
{
$Score = $Score+$Val[$i];
}
}
} //**** The following is the HTML part of the code(form)
<form action = "A.php" method ="POST" enctype="multipart/form-data">
<label for="Position">Position:</label><input type="type" name="Position" size="35" /><br />
</p>
<p>
<!-- <label for="DutiesDesc">Duties Description: </label><textarea name="DutiesDesc" cols="30" rows="5" /></textarea>--> <br />
Job Description
<select name="DutiesDesc[]" size=5 multiple="multiple">
<option value="<?php echo $Arow['TextF1']?>"><?php echo $Arow['TextF1']?></option>
<option value="<?php echo $Arow['TextF2']?>"><?php echo $Arow['TextF2']?></option>
<option value="<?php echo $Arow['TextF3']?>"><?php echo $Arow['TextF3']?></option>
<option value="<?php echo $Arow['TextF4']?>"><?php echo $Arow['TextF4']?></option>
<option value="<?php echo $Arow['TextF5']?>"><?php echo $Arow['TextF5']?></option>
<option value="<?php echo $Arow['TextF6']?>"><?php echo $Arow['TextF6']?></option>
<option value="<?php echo $Arow['TextF7']?>"><?php echo $Arow['TextF7']?></option>
<option value="<?php echo $Arow['TextF8']?>"><?php echo $Arow['TextF8']?></option>
<option value="<?php echo $Arow['TextF9']?>"><?php echo $Arow['TextF9']?></option>
<option value="<?php echo $Arow['TextF10']?>"><?php echo $Arow['TextF10']?></option>
<option value="<?php echo $Arow['TextF11']?>"><?php echo $Arow['TextF11']?></option>
</select><br />
The values in the array
$SkillsArraydo not have the same index as your$Textarray. If you select the 3rd (lets say the value is “c”) and 5th (e.g. “e”) item in your list, the array$SkillsArraywill contain the following:So what you need is a simple search over your
$SkillsArray, since you can’t rely on the indexes being conform with your$Textarray.Please do remember to check, if
$SkillsArrayis indeed an array. If the user doesn’t check any skills, the functionarray_searchwill returnfalsefor every item, which will result in the maximum score.Documentation for functions: count, array_search, is_array
The