My objective is to:
1.) Select a random word from a MySQL database table
2.) Check whether the word is positive or negative (e.g., "laughter"= positive word "death" = negative word)
3.) Check if the word has already been used for this user session (from response data in a table)
.... If so go to step 1 and select a new random word else continue to step 5.
5.) Check if newly selected word's property of being either positive or negative has occurred to many times. (from response data in table count all words used that are positive)
.... if count totals more than (12 for positive or 9 for negative) then go back to step 1. and select new word.
.... else return selected word.
My approach:
I created:
- one function to select a random word from table
iat_get_random_word()
one function to check if the word is positive or negative iat_check_word_valence($new_word)
one function to check it the word has been used
iat_check_if_used($sid,$new_word,$stage)
one function to check total positive or negative words used
iat_check_total_valence($sid,$valence,$stage);
My code below works well with the exception this last function ...iat_check_total_valence.
so if there are already 12 positive words it will still return a positive word and it should not. Any advice would be greatly appreciated. Thanks so much!
My logic is:
function set_word($sid){
$new_word = iat_get_random_word();
$valence = iat_check_word_valence($new_word);
$stage = get_stage($sid);
$stage_count = count_stage($sid, $stage);
$valcount = iat_check_total_valence($sid,$valence,$stage);
if($stage_count > 21){
$stage = $stage++;
}
/*if($valence == "pos" && $stage == "1"){
$valence_allowed = 12;
}
if($valence== "neg" && $stage == "1"){
$valence_allowed = 9;
}
if($valence == "pos" && $stage == "2"){
$valence_allowed = 12;
}
if($valence== "neg" && $stage == "2"){
$valence_allowed = 9;
}
if($valence == "pos" && $stage == "3"){
$valence_allowed = 9;
}
if($valence== "neg" && $stage == "3"){
$valence_allowed = 12;
}
if($valence == "pos" && $stage == "4"){
$valence_allowed = 9;
}
if($valence== "neg" && $stage == "4"){
$valence_allowed = 12;
}
while(iat_check_if_used($sid,$new_word,$stage) == "1"){
$new_word = iat_get_random_word();
$valence = iat_check_word_valence($new_word);
while(iat_check_total_valence($sid,$valence,$stage) > $valence_allowed){
$new_word = iat_get_random_word();
$valence = iat_check_word_valence($new_word);
}
}
return "word_stim=".$new_word."&val=".$valence;
}