- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
$scales = db_select('_scale', 'q')
->condition('q.gender', $gender)
->fields('q', array('id'))
->execute();
$i = 1;
while ($scale = $scales->fetchObject()) {
$raw_score = 0;
$query = db_select('_scale_question', 'q')
->condition('q.scale_id', $scale->id)
->fields('q')
->execute();
while ($item = $query->fetchObject()) {
$user_answer = db_select('_user_answer', 'q')
->condition('q.question_id', $item->question_id)
->condition('q.result_id', $result_id)
->fields('q', array('answer'))
->execute()
->fetchField();
if ($user_answer == $item->expected_answer) {
$raw_score++;
}
}
$raw_scores_item['scale_id'] = $scale->id;
$raw_scores_item['score'] = $raw_score;
$raw_scores[$i] = $raw_scores_item;
$i++;
}
Drupal 7, SQL-запросы с DB API Drupal в двойном цикле(!).
...А заменить можно 1 нормальным SQL-запросом.